当我尝试编辑数据库时,出现此错误:
SQLSTATE [HY093]:参数号无效:参数未定义
有关于此错误的问题,但它们似乎并不适用于此案例。谢谢!
<php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
require_once 'db.php';
if(isset($_POST['submit']))
{
$get_id=$_REQUEST['id'];
$name=$_POST['name'];
$surname=$_POST['surname'];
$pic = $_FILES['pic']['name'];
try{
move_uploaded_file($pic,"uploads/$pic");
$stmt = $db_con->prepare("UPDATE posts SET
name=:name,surname=:surname,pic=:pic WHERE id=:GET_id");
$stmt->bindParam(":id", $id);
$stmt->bindParam(":name", $name);
$stmt->bindParam(":surname", $surname);
$stmt->bindParam(":pic", $pic);
if($pic=="") {
move_uploaded_file($pic,"uploads/$pic");
("UPDATE posts SET name=:name, surname=:surname, pic=:pic WHERE id=:GET_id");
$stmt->bindParam(":id", $id);
$stmt->bindParam(":name", $name);
$stmt->bindParam(":surname", $surname);
$stmt->bindParam(":pic", $pic);
}
if($stmt->execute())
{
echo "<script>alert('Successfully Updated!!!'); window.location='index.php'</script>";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
答案 0 :(得分:1)
在两个查询
中将GET_id
更改为id
WHERE id=:id
并且在此处将$get_id
更改为$id
,因为您在下面的代码中使用了$id
$id = $_REQUEST['id'];