2015-04-25 14 views
0
$image= addslashes($_FILES['image']['tmp_name']); 
$name= addslashes($_FILES['image']['name']); 
$image= file_get_contents($image); 
$image= base64_encode($image); 
$studentid = 1; $con=mysql_connect("localhost","root","root"); 
mysql_select_db("secure_login",$con); 
$qry="INSERT into images (name,image,studentid) values ('$name','$image','$studentid')"; 
$result=mysql_query($qry,$con); 

在這裏,我試圖將圖像插入到MySQL中。當我將insert更改爲update時,整個代碼崩潰了,我無法修復它。使用「插入」時圖像上傳,但使用「更新」時不會上傳圖像

我知道這是基本的語法:

$qry="UPDATE images SET name = $name, image = $image, studentid=$studentid"; 

但後來這不起作用。

+0

在更新查詢中使用'WHERE' –

回答

0

您更新查詢將

$qry="UPDATE images SET name = '".$name."', image = '".$image."', studentid='".$studentid."'"; 

此查詢更新你的整個表使用WHERE條款只更新特定的列

1

您在表中插入新行。您更新現有的行。所以,當你運行UPDATE查詢時,你必須指定你正在更新的行。你不能用INSERT替換UPDATE。 更新你的代碼:

$qry="UPDATE images SET name = '$name', image = '$image', studentid='$studentid' WHERE id='$rowid'"; 

另外請注意,在您的查詢,你應該換用「的價值觀,以確保對MySQL將如何處理它們。