UPDATE QUERY没有错误,但查询没有执行

时间:2018-02-20 11:36:57

标签: php mysqli

我有一个更新查询,我一直试图使用他的电子邮件iD和这类表名来更新用户的密码。

不幸的是,查询在运行时没有给出任何错误,但也没有执行。

查询如下:

<?php include('index.php'); ?>
<?php include('db.php'); ?>

<?php



$email = $_POST['email'];
$who = $_POST['who'];
$password = md5($_POST['password']);

$date = date_default_timezone_set('Asia/Kolkata');
$date = date('M-d,Y H:i:s');
$date2 = date('M-d,Y');


$conn = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}


$sql = "UPDATE $who SET password = '$password'
WHERE email = '$email'";
if ($conn->query($sql) === TRUE) {

echo '<script language="javascript">';
echo 'alert("Password Updated Successfully. Please LogIn")';
echo '</script>';
echo '<a href="index.php"></a>';
}
else {
    echo "ERROR" . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

我甚至单独检查每个变量是否传递值。比如$ who变量,电子邮件和密码变量,它们都是传递值。但查询不是更新表格单元格。

表格相同:

<?php 
    $email = $_GET["id"];
    $who = $_GET["id2"];
?>

        <!-- Banner Section -->
        <section id="banner" class="banner-slider">
            <div class="banner-img-slider">
                <div>
                    <div class="banner-thumb"><img src="assets/images/banner-img/team-banner.jpg" alt="" class="hide" /></div>
                </div>
            </div>
            <div class="blue-overlay"></div>
            <div class="banner-text-wrapper">
                <div class="container">
                    <div class="banner-text">
                        <div class="row">
                            <div class="col-md-6 col-md-offset-3">
                                <form action="passsetinput.php" method="post">
                                <h2 style="font-family: Verdana, Geneva, sans-serif; color:lightgreen; font-size:35px;"><strong>Set Password</strong></h2><br>
                                <input type="text" name="email" value="<?php echo $email; ?>" disabled style="width:250px;height:35px;padding-left:20px;border-radius:15px;" /><br><br>
                                <input type="password" name="password" placeholder="Please Type Password Here..." style="width:250px;padding-left:20px;border-radius:15px;height:35px;" /><br><br>
                                <input type="hidden" name="who" value="<?php echo $who; ?>" />
                                <button class="button"><strong>Confirm Password</strong></button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!-- Content Start -->

感谢任何帮助..

1 个答案:

答案 0 :(得分:0)

如评论中提到的那样(并且由Harish K批准),有时日期基础不允许在没有&#34; id / primaryKey-part&#34;的情况下更新-QUERIES。在WHERE子句中。

简单的解决方案:修改您的查询,例如&#34; UDATE ... WHERE ... AND id&gt; 0&#34 ;. (我认为存在一个名为id的主键,它是数字类型的。)