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.

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

Use UPDATE query instead of INSERT. INSERT will add new row but UPDATE will update your existing data.

You have to update the row if the row where you want to add image link is already exist. So use UPDATE Query. and debug wether table is updated or not.

check in table or use or die(); after the query