duanfan8360 2013-06-17 05:11
浏览 17

PHP - 如何将数据添加到数据库中的现有行

I created a login page that when user login redirect to a pictures.php, pictures page should contains the images of the user , I already create upload page to upload image to file directory and when the user upload an image the image link is added to a new row in the database, I need to add the image link to an exist row of the user,I already created a session for user when logged in.

So I need to add the image link to an exist row of the user.

This is the code that insert the image to a file directory and save its link to a new row of the database.

<?php
$name = $_FILES["myfile"] ["name"];
$type = $_FILES["myfile"] ["type"];
$size = $_FILES["myfile"] ["size"];
$temp = $_FILES["myfile"] ["tmp_name"];
$name = $size.$size .$name ;
$error = $_FILES["myfile"] ["error"];

if ($error > 0){
die ("Error uploading image");
}else{
mysql_query("INSERT INTO userid (imageid) VALUES ('.$name')");
move_uploaded_file($temp,"uploaded/".$name);
echo "Upload Completed";

}

?>

And the upload form is

<html>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="myfile">
<input type="Submit" value="Upload"> 
</form>
</html>

So how to the image link to an exist row of the user.

  • 写回答

3条回答 默认 最新

  • doujian3401 2013-06-17 06:09
    关注

    Use mysql_query("UPDATE $table_name SET imageid='{$name}' WHERE userid=$userid") Of course substituting variables and columns with correct values

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看