doubai9014 2012-10-09 00:53
浏览 55
已采纳

使用PHP和MySQL创建图像选择表单

I'm trying to have a form that when you select the radio button it will select the image and query into the server; now I'm not quite sure as to how this would be accomplished because when I select any other then the original it doesn't seem to work. My form Code (Well. The important part)

<form action="update_image.php" method="post">
<input type="hidden" name="page" value="Index" />
<td><center><input name="image" type="radio" value="images/cartoon/2ofus.png" /></center></td>
<td><center><input name="image" type="radio" value="img src='images/cartoon/3lb_Bruce.png" /></center></td>
<td><center><input name="image" type="radio" value="img src='images/cartoon/bearry.png" /></center></td>
<td><center><input name="image" type="radio" value="img src='images/cartoon/Bemmer.png" /></center></td>
<input type="submit" value="Update" />
   </form>

My Query is as follows:

$link     = mysqli_connect("$server", "$user", "$pass", "$webdb");
    $page = mysqli_real_escape_string($link, (string) $_POST['page']);
    $content = mysqli_real_escape_string($link, (string) $_POST['image']);
$query = "UPDATE `pages` 
              SET `image`='<$image>' 
              WHERE `name`='$page'";

    mysqli_query($link, $query);
    mysqli_close($link);

?>

It's not the best in the world, but overall I think it should work solidly, but it doesn't, so if anyone might know why it'd be great. Thanks.

The first Is the original. Sorry for not specifying.

  • 写回答

2条回答 默认 最新

  • douba8819 2012-10-09 02:00
    关注

    This is what I understood from your question. You have a specific image in the home page, whose src is queried from the database and can be updated by the form given by you.

    Change the form to :

     <form action="update_image.php" method="post">
          <input type="hidden" name="page" value="Index" />
      <td><center><input name="image" type="radio" value="images/cartoon/2ofus.png" /></center>   </td>
      <td><center><input name="image" type="radio" value="images/cartoon/3lb_Bruce.png" /></center></td>
      <td><center><input name="image" type="radio" value="images/cartoon/bearry.png" /></center></td>
     <td><center><input name="image" type="radio" value="images/cartoon/Bemmer.png" /></center></td>
     <input type="submit" value="Update" />
    

    Change the query to:

      $query = "UPDATE `pages` 
              SET `image`='$image' 
              WHERE `name`='$page'";
    

    In the index page, after querying the tables pages, use the result in the image tag like :

     print "<img src='{$row['image']}'/>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大