我想在同一个表中保存图片的文件路径和图像名称,但当然要保存单独的字段。我该如何正确执行?我确定下面的代码中存在严重错误,但我无法发现它。谢谢。
$sess_userid = mysql_real_escape_string($_SESSION['userid']);
$Image = mysql_real_escape_string($_FILES['file']['name']);
$PortraitPath = mysql_real_escape_string('profileportraits/' . $_FILES['file']['name']);
$query = "UPDATE Members
SET PortraitPath = '$PortraitPath'
WHERE fldID='$sess_userid'";
$query2 = "UPDATE Members
SET Image = '$Image'
WHERE fldID='$sess_userid'";
$result = mysql_query($query) or trigger_error(mysql_error().$query);
$result2 = mysql_query($query2) or trigger_error(mysql_error().$query2);
答案 0 :(得分:7)
您可以同时更新同一个表格中的多个字段。
$query = "UPDATE Members
SET PortraitPath = '$PortraitPath',
Image = '$Image'
WHERE fldID='$sess_userid'";
mysql_query($query) or trigger_error(mysql_error().$query);
答案 1 :(得分:2)
使用这样的逗号:
UPDATE Members
SET PortraitPath = '$PortraitPath',
Image = '$Image'
WHERE fldID = '$sess_userid'