dongtongjian3127 2017-03-11 11:57
浏览 31
已采纳

尝试通过webapp编辑数据库时出现错误SQLSTATE [HY093]

When I try to edit the database, I get this error:

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

There are questions related to this error, but they don't seem to apply to this case. Thanks!!

<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();
        }  
    }
?>
  • 写回答

1条回答 默认 最新

  • du4010 2017-03-11 12:01
    关注

    Change GET_id to id in both query

    WHERE id=:id
    

    and also here change $get_id to $id as you used $id in below code

    $id = $_REQUEST['id'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题