im currently working on a webshop and im now busy working on a reset password function. People enter in their email and a sql query checks if the email exists. If it exists a random string is created and will be inserted in the database. Now the problem is that the query with the random string is successfull but the data isnt being updated. Hopefully someone can help me. The code that i am using:
//Import database connection in variable $conn
require("dbh.inc.php");
//Load composer's autoloader
require 'vendor/autoload.php';
//Load variable with password
require 'credentials.php';
//Escape bullshit
$email = $conn->real_escape_string($_POST['email']);
//Make all data in $email lowercase
$email = strtolower($email);
//Put SQL query in var $sql
$sql = "SELECT user_Id FROM customers WHERE user_Email='$email'";
//Execute query and put results in var $data
$data = $conn->query($sql);
//If the email exists
if ($data->num_rows > 0) {
//Random characters
$str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
//Shuffle all data in var $str
$str = str_shuffle($str);
//Select only the data after 40th position
$str = substr($str,40);
//The url that will be send to the user
$url = "http://example.com/users/resetPassword.php?token=$str&email=$email";
//Execute SQL query
$query = $conn->query("INSERT customers SET user_ResetToken='$srt' WHERE user_Email='$email'");