0

I have an Update query, which i been trying to use to update the password of user using his email iD and this category of table name.

Unfortunately the query isn't giving any error when runned but doesn't executing either.

the query goes as:

<?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();
?>

I even checked each variable individually that is it passing values or not. like the $who variable, email and password variables, they are passing values. but the query isn't updating the table cell.

Form for the same:

<?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 -->

Any help is appreciated..

Harish K
  • 37
  • 7

1 Answers1

0

Like mentioned in the comments (and approved by Harish K), sometimes datebases doesn't allow Update-QUERIES without an "id/primaryKey-part" in the WHERE-clause.

Simple solution: Modify your query like "UDATE ... WHERE ... AND id > 0". (I asume there exists a primary key called id which is of numeric type).

Flocke
  • 764
  • 6
  • 14