Php 更新图像路径

Php 更新图像路径,php,mysql,sql,image,Php,Mysql,Sql,Image,我对PHP编程相当陌生,我环顾了四周,但仍然感到困惑。我正在尝试更新users表中的映像路径,但我不太确定如何更新。这是我将图像放入数据库的代码,它可以插入,但我不确定如何更新数据库中的图像路径,以使用新插入的图像,而不是用户创建帐户时选择的图像 // Make sure we didn't have an error uploading the image ($_FILES[$image_fieldname]['error'] == 0) or handle_error("the server

我对PHP编程相当陌生,我环顾了四周,但仍然感到困惑。我正在尝试更新users表中的映像路径,但我不太确定如何更新。这是我将图像放入数据库的代码,它可以插入,但我不确定如何更新数据库中的图像路径,以使用新插入的图像,而不是用户创建帐户时选择的图像

// Make sure we didn't have an error uploading the image
($_FILES[$image_fieldname]['error'] == 0)
or handle_error("the server couldn't upload the image you selected.",
$php_errors[$_FILES[$image_fieldname]['error']]);

// Is this file the result of a valid upload?
@is_uploaded_file($_FILES[$image_fieldname]['tmp_name'])
 or handle_error("you were trying to do something naughty.  Shame on you!",
"upload request: file named " .
"'{$_FILES[$image_fieldname]['tmp_name']}'");

// Is this actually an image?
@getimagesize($_FILES[$image_fieldname]['tmp_name'])
 or handle_error("you selected a file for your picture " .
"that isn't an image.",
"{$_FILES[$image_fieldname]['tmp_name']} " .
"isn't a valid image file.");

// Name the file uniquely
$now = time();
while (file_exists($upload_filename = $upload_dir . $now .
'-' .
$_FILES[$image_fieldname]['name'])) {
$now++;
}

// Finally, move the file to its permanent location
@move_uploaded_file($_FILES[$image_fieldname]['tmp_name'], $upload_filename)
 or handle_error("we had a problem saving your image to " .
"its permanent location.",
"permissions or related error moving " .
"file to {$upload_filename}");

$insert_sql = "UPDATE users set user_pic_path WHERE user_id = $user_id =
replace(user_pic_path, '$upload_filename', '$upload_filename' );

//insert the user into the database
mysql_query($insert_sql);
</code>
编辑: 我丢失了一个“我修复了,现在没有SQL错误,它将图片放入数据库,但不替换数据库中的图像路径。我一直在使用$insert_SQL,但它仍然不使用新的图像路径更新数据库,我能做什么?这是我的新更新代码:

<code>
$insert_sql = "UPDATE users WHERE user_id = $user_id set user_pic_path =
replace(user_pic_path, '$upload_filename', '$upload_filename')";
</code>

在最后一行中,插入对SQL的测试:

$insert_sql = "UPDATE users WHERE user_id = $user_id set user_pic_path = replace(user_pic_path, '$upload_filename', '$upload_filename')";

// check the query
echo $insert_sql."<br />";

//insert the user into the database
mysql_query($insert_sql);
$insert\u sql=“更新用户,其中用户id=$user\u id设置用户\u pic\u路径=替换(用户\u pic\u路径,$upload\u filename',$upload\u filename”)”;
//检查查询
echo$insert_sql.“
”; //将用户插入数据库 mysql\u查询($insert\u sql);

然后你可以观察你的查询即将运行,在PHPMyAdmin中测试它,找出它应该是什么。对于其他关键变量也值得这么做。更好的是,你应该编写一个“调试”“函数,它记录服务器上一个文件中发生的情况,以便在发生错误时,您可以跟踪该文件的详细信息,包括每个文件中关键变量的值。

因此,您没有任何计划或编码技能,对吗?”?我敢打赌,这里有一些文档,你是从那里得到这段代码的。你认为
user\u pic\u path
代表什么?我确实有一些编码技能,我只是对PHP相对较新,并一直坚持这一点。我不确定在$insert_sql中放入什么来更新数据库中的图像路径。将图像放入数据库可以很好地工作,但它不会替换路径,这正是我想要做的。实际上,你应该会遇到SQL错误。是的,我遇到了一个内部服务器错误,它根本没有发布,你知道我可以用我的更新代码来做什么吗?我仍然会遇到SQL/内部服务器错误。我想我的问题是更新代码,但我不知道如何去改变它使其工作感谢你的帮助,我找到了答案。