drmq16019 2016-04-14 12:51
浏览 13
已采纳

当我在那里使用if else时,获取mysql的错误

getting error for mysql when i am using if else in there. i dont know what should i do and when i am using duplicate condition to update then it not woring i am not be able to find where is error

this is the error which is i am getting.

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

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt=$conn->prepare("SELECT uniqueid FROM hotelcarttemp WHERE uniqueid=:uniqueid");
$stmt->execute(array(':uniqueid'=>$uniqueid));
$count=$stmt1->rowCount();
echo "count-".$count;
if($count>0)
   {
    $sql = "UPDATE hotelcarttemp SET `hotelname`='".$hotelname."',`roomtype`='".$roomtype."',`checkin`='".$checkin."',`checkout`='".$checkout."',`Country`='".$Country."',`Destination`='".$Destination."',`price`='".$price."' WHERE uniqueid='".$uniqueid."'";
    echo "sql- ".print_r($sql);
        $stmt = $conn->prepare($sql);
        // echo print_r($stmt);
        $stmt->execute();
   }
   else
   {
       $sql = "INSERT INTO hotelcarttemp (timestamp, packageid, uniqueid, hotelname, roomtype, checkin, checkout, Country, Destination, hoteldetail, price)
        VALUES ('"  
        .$timestamp."','"
        .$packageid."','"
        .$uniqueid."','"
        .$hotelname."','"
        .$roomtype."','"
        .$checkin."','"
        .$checkout."','"
        .$Country."','"
        .$Destination."','"
        .addslashes($hoteldetail)."','"
        .$price."'
        )"; 
        // echo "sql- ".print_r($sql);
        $stmt = $conn->prepare($sql);
        // echo print_r($stmt);
        $stmt->execute();
   }
}
catch(PDOException $e) {
  echo 'ERROR:' . $e->getMessage();
} here
  • 写回答

1条回答 默认 最新

  • doubenggua9430 2016-04-14 12:54
    关注

    Your SELECT query where condition is WHERE uniqueid=:uniqueid

    And you are binding username to it

    $stmt->execute(array(':username'=>$uniqueid));//:username invalid parameter
    

    Change this to

    $stmt->execute(array(':uniqueid'=>$uniqueid));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?