bind_param()没有被执行

时间:2016-05-31 09:33:38

标签: php mysql

我在mysqli和php上准备好语句时遇到了问题。

我有一个表单,用户可以更改他们的电子邮件地址,但似乎bind_param('si',$ value,$ value)存在问题;

我已经尝试过不同的东西来修复它但到目前为止还没有任何工作。 我希望你能发现错误。

修改

由于评论中的一些讨论,一些额外的信息:

  • 我已经尝试过许多方法来解决问题。
  • try catch没有错误,error_reporting没有错误
  • bind_param()没有做任何事情,它只是跳出代码。 bind_param()之后的所有内容都没有执行
  • 进一步测试表明,由于@Vijay Dohare
  • ,$ ustmt为NULL

HTML表单

<form action="" method="post" name="emailReset" id="emailReset" class="form-reset">
  <input type="hidden" name="UID" id="UID" value="<?php echo $id; ?>">

  <label class="reset-label sr-only" for="newEmail">Neue E-Mail-Adresse</label>
  <input name="newEmail" id="newEmail" type="email" class="form-control" placeholder="Neue E-Mail-Adresse" required /><br />

  <label class="login-label sr-only" for="verifyEmail">E-Mail-Adresse wiederholen</label>
  <input name="verifyEmail" id="verifyEmail" type="email" class="form-control" placeholder="E-Mail-Adresse wiederholen" required /><br />

  <button name="emailReset" id="emailReset" class="btn btn-lg btn-primary btn-block" type="submit"><i class="fa fa-repeat"></i> E-Mail-Adresse &auml;ndern</button>
</form>

PHP代码:

    if(isset($_POST['emailReset'])) {
        $UID = intval($_POST['UID']);
        $newEmail = $_POST['newEmail'];
        $verifyEmail = $_POST['verifyEmail'];

        echo nl2br($UID . "\n");
        echo nl2br($newEmail . "\n");
        echo nl2br($verifyEmail . "\n");

        if($newEmail == $verifyEmail) {
            $emailsEqual = true;
            $escapedNewEmail = escape($newEmail);

            echo nl2br('' . "\n");
            echo nl2br('EscNewEmail: ' . $escapedNewEmail . "\n");
            echo nl2br('' . "\n");

            $ustmt = $con->prepare('UPDATE users SET Email = ? WHERE ID = ?');
            echo nl2br(is_null($con) ? 'Con, no.' : 'Con, yes' . "\n");
            echo nl2br(empty($con) ? 'Con, no.' : 'Con, yes' . "\n");
            $ustmt->bind_param('si', $escapedNewEmail, $UID); //DOESN'T WORK!!!
            $ustmt->execute();

            $affectedRows = $ustmt->affected_rows;

            if($affectedRows > 0) {
                $updated = true;
                echo nl2br($affectedRows . ' Rows affected.' . "\n");
            } else {
                $updated = false;
                echo nl2br($affectedRows . ' Rows affected.' . "\n");
          }

          $ustmt->close();  
      } else {
          $passwordsEqual = false;
      }
  }

输出:

value from UID
value from email
value from email

EscNewEmail: escaped value from email

Con, yes
Con, yes

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码检查数据库连接

echo nl2br($con->connect_errno ? 'Con, no.' : 'Con, yes' . "\n");

因为如果连接错误,连接将返回false值

我认为您正在连接到像

这样的数据库
$con = new mysqli('localhost', 'user', 'pass', 'database');