PHP别的不工作

时间:2018-06-18 03:57:45

标签: php

为什么我的最后一个$msg无效?即使我这样做也是正确的。请帮助解决我的问题。

代码:

 //Cancel button start
 if (isset($_POST['cncl'])) {
     $sql = "DELETE FROM users WHERE Email_ID='$email' AND token='$token' AND isEmailConfirmed='PENDING' AND isMobileConfirmed='PENDING'";
     ///     
     if ($con - > query($sql) === TRUE) {
         $msg = "<div class='alert-box success'><span>Registration cancelled. < /
         span > < /div > ";
     } else {
         $msg = "<div class='alert-box warning'><span>Registration cancelled! Please signup again if you create again!</span> < /
         div > ";
     }

     ///
 }
 //Cancel button end

2 个答案:

答案 0 :(得分:0)

你可以检查,是否删除记录。

if (isset($_POST['cncl'])) {
     $result = $con->query("DELETE FROM users WHERE Email_ID='$email' AND token='$token' AND isEmailConfirmed='PENDING' AND isMobileConfirmed='PENDING'");
     ///     
     if ((mysql_affected_rows($con) > 0) ) {
         $msg = "<div class='alert-box success'><span>Registration cancelled. < /
         span > < /div > ";
     } else {
         $msg = "<div class='alert-box warning'><span>Registration cancelled! Please signup again if you create again!</span> < /
         div > ";
     }

如果它将返回大于0的值,则记录已删除或如果它将返回0,则记录不删除。

答案 1 :(得分:0)

mysqli->query()SELECT语句一起使用会返回mysqli_result的实例。它与true (=== true)不同,但也不代表错误。

此外,$result未定义。您可以尝试这个

if (isset($_POST['cncl'])) {
     $sql = "DELETE FROM users WHERE Email_ID='$email' AND token='$token' AND isEmailConfirmed='PENDING' AND isMobileConfirmed='PENDING'";
     ///     
     if (($result = $con->query($sql)) !== FALSE) {
         $msg = "<div class='alert-box success'><span>Registration cancelled. < /
         span > < /div > ";
     } else {
         $msg = "<div class='alert-box warning'><span>Registration cancelled! Please signup again if you create again!</span> < /
         div > ";
     }

     ///
 }