更新列时,查询/预准备语句中没有使用索引

时间:2015-04-04 19:27:58

标签: php mysqli

我有这个错误:

  

查询/预准备语句中没有使用索引UPDATE成员SET fname =?,mname = ?, lname =?用户名=?

请记住,这只是登录用户的脚本,因此会话将始终启动。

此脚本用于更改/更新当前名称(名字,中间名和姓氏)。数据库中的列是fname,mname和lname,都设置为varchar(36)(因为用户的第一个,中间名或姓氏不太可能超过36个字母)

这是我的表格:

<form method="POST" action="">

<input type="text" name="fname" class="input" placeholder="First Name"><br>
<input type="text" name="mname" class="input" placeholder="Middle Name"><br>
<input type="text" name="lname" class="input" placeholder="Last Name"><p>
<input type="submit" name="sbmtnm" class="buttondiv" value="Submit"><p>
</form>

这是我更新名称的PHP代码:

    <?php 
mysqli_report(MYSQLI_REPORT_ALL);

    if(isset($_POST['sbmtnm'])){
        if(empty($_POST['fname']) && ($_POST['lname'])) {
            echo "<font color='#DB4D4D'>First Name or Last name field is blank!</font>";
        }
        else { 

            $_POST['fname'] = $fname;
            $_POST['mname'] = $mname;
            $_POST['lname'] = $lname;
            $_SESSION['username'] = $username;

            $sqlnm = "UPDATE members SET fname = ?, mname = ?, lname = ? WHERE username = ?";

            // I also tried this :
            $sqlnm = "UPDATE members SET (fname, mname, lname) VALUES (?, ?, ?) WHERE username = ?";
            //↑ This code shows another error message : You have an error in your SQL syntax; check the             
            //manual that corresponds to your MySQL server version for the right syntax to use near '(fname, 
            //mname, lname) VALUES (?, ?, ?) WHERE username = ?


            $stmt = $mysqli->prepare($sqlnm);
            if(false===$stmt){
                die('prepare() failed:' . $mysqli->errno. htmlspecialchars($mysqli->error));
            }
            $check = $stmt->bind_param('ssss', $fname, $mname, $lname, $username);
            if(false===$check){
                die('bind_param() failed:' . htmlspecialchars($stmt->error));
            }
            $ok = $stmt->execute();
            if(false===$ok){
                die('execute() failed:' . htmlspecialchars($stmt->error));
            }
            $stmt->close();

            if($ok == true){
                echo "<p><font color='#00CC00'>Your name has been successfuly submitted.</font>";
            }
        }
    }


?>

我真的不知道问题在哪里......

1 个答案:

答案 0 :(得分:0)

尝试发表评论mysqli_report(MYSQLI_REPORT_ALL);,因为有些实例会报告错误太多,并且可能导致您的代码无法完全执行。