0

当我尝试使用 mysqli 准备好的语句更新查询时,出现以下错误。错误消息有什么问题,为什么它是意外的?任何帮助。

Parse error: syntax error, unexpected '$prob' (T_VARIABLE)

这是查询

$mysqli = new mysqli("localhost", "root", "", "newlogin");
        if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
        }
        $check = $mysqli->prepare("select * from `vpb_uploads` where `username` = ? and `firstname` = '' and `image_one` != ''");
        $check->bind_param('s', $username);
        $check->execute();
        $check->store_result();

        if($check->num_rows < 1)
        {
            echo '<div class="vpb_error_info" align="left">Sorry, It seems you have not added any file yet.<br>Please click on the Add Files button to first of all add at least one file before submitting your details. Thanks...</div>';
        }
        else
        {
        $firstname = trim(strip_tags($_POST["firstname"]));
        $lastname = trim(strip_tags($_POST["lastname"]));

        if( $prob = $mysqli->prepare("update `vpb_uploads` set `firstname` = ?, `lastname` = ? where `username` = ? and `firstname` = '' and `image_one` != ''")
        $prob->bind_param('sss', $firstname, $lastname, $username);
        $prob->execute();
        )

        {
                echo '<font style="font-size:0px;">success</font>';
                echo '<div class="vpb_error_info" align="left">Congrats <b>'.$firstname.' '.$lastname.'</b>, your details have been submitted successfully. Thanks...</div>';
        }
4

2 回答 2

0

乍一看,您的错误似乎在第 19 行:

if($prob = $mysqli->prepare("
  UPDATE `vpb_uploads`
  SET `firstname` = ?,
      `lastname` = ?
  WHERE `username` = ?
  AND `firstname` = ''
  AND `image_one` != ''
")

  $prob->bind_param('sss', $firstname, $lastname, $username);
  $prob->execute();

)

您在语句本身中有bind_paramandexecute函数。if它需要是:

if($prob = $mysqli->prepare("
  UPDATE `vpb_uploads`
  SET `firstname` = ?,
      `lastname` = ?
  WHERE `username` = ?
  AND `firstname` = ''
  AND `image_one` != '';
") {
  $prob->bind_param('sss', $firstname, $lastname, $username);
  $prob->execute();
}

如果您对括号感到困惑,您的结束代码应如下所示:

$mysqli = new mysqli("localhost", "root", "", "newlogin");
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$check = $mysqli->prepare("select * from `vpb_uploads` where `username` = ? and `firstname` = '' and `image_one` != '';");
$check->bind_param('s', $username);
$check->execute();
$check->store_result();

if($check->num_rows < 1) {
    echo '<div class="vpb_error_info" align="left">Sorry, It seems you have not added any file yet.<br>Please click on the Add Files button to first of all add at least one file before submitting your details. Thanks...</div>';
} else {
  $firstname = trim(strip_tags($_POST["firstname"]));
  $lastname = trim(strip_tags($_POST["lastname"]));
}

if($prob = $mysqli->prepare("update `vpb_uploads` set `firstname` = ?, `lastname` = ? where `username` = ? and `firstname` = '' and `image_one` != '';")) {
  $prob->bind_param('sss', $firstname, $lastname, $username);
  $prob->execute();
  echo '<font style="font-size:0px;">success</font>';
  echo '<div class="vpb_error_info" align="left">Congrats <b>'.$firstname.' '.$lastname.'</b>, your details have been submitted successfully. Thanks...</div>';
}
于 2013-04-08T22:30:33.503 回答
0

试试这个代码:

$mysqli = new mysqli("localhost", "root", "", "newlogin");
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$check = $mysqli->prepare("select * from `vpb_uploads` where `username` = ? and `firstname` = '' and `image_one` != ''");
$check->bind_param('s', $username);
$check->execute();
$check->store_result();

if($check->num_rows < 1){
     echo '<div class="vpb_error_info" align="left">Sorry, It seems you have not added any file yet.<br>Please click on the Add Files button to first of all add at least one file before submitting your details. Thanks...</div>';
} else {
    $firstname = trim(strip_tags($_POST["firstname"]));
    $lastname = trim(strip_tags($_POST["lastname"]));

    $prob = $mysqli->prepare("update `vpb_uploads` set `firstname` = ?, `lastname` = ? where `username` = ? and `firstname` = '' and `image_one` != ''") ;
    if ($prob){
        $prob->bind_param('sss', $firstname, $lastname, $username);
        $success = $prob->execute();
        if ($success){
            echo '<font style="font-size:0px;">success</font>';
            echo '<div class="vpb_error_info" align="left">Congrats <b>'.$firstname.' '.$lastname.'</b>, your details have been submitted successfully. Thanks...</div>';
        }
     }
}
于 2013-04-08T22:31:33.253 回答