Mysqli准备声明插入不起作用

时间:2013-07-05 11:44:25

标签: mysqli prepared-statement

我对这段代码的错误感到厌烦:这是我准备的代码,稍后会从表单中获取用户输入。现在,我正在尝试完善插入代码。

    <?php
    $mysqli = new mysqli("connection info here");
    // Check connection
    if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }

    /* Create a prepared statement */
    if($stmt = $mysqli -> prepare("insert into carpool(Destination, No_of_seats_available) values(?,?)"))
    {
    /* Bind parameters
    s - String, b - Boolean, i - Integer etc */
    $Destination='vishal';
    $No_of_seats_available=25;
    $stmt -> bind_param("si", $Destination, $No_of_seats_available);

    /* Execute it */
    $result=$stmt -> execute();
    $rowsAffected = $stmt->affected_rows;

    if($result > 0){
  echo "Rows Affected: ".$rowsAffected;
  }
   else{
  echo 'Sorry, Please try after some time';
  }
  }
  mysqli_close($mysqli);
  ?>

我收到“抱歉,请稍等一会儿”错误。我认为这意味着直到该行代码的所有代码都被正确执行了?我检查了表和字段名称,所有都正确匹配。但是,表中没有插入并显示错误。 我错过了什么?

0 个答案:

没有答案