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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度