I am trying to make a remember me option in my login form. Each time I try to update table with the token value, this value specifically does not update and always return empty after the update process, although the cookies and sessions are already created. Here is my php code.
<?php
$dbc=mysqli_connect('localhost','root','','store') or die('Can\'t connect.');
session_start();+
{
if(isset($_POST['submit_login'])) {
$login_username=$_POST['user_name_login'];
$login_password=$_POST['password_login'];
$statement=mysqli_stmt_init($dbc);
if (mysqli_stmt_prepare($statement, "SELECT * FROM customers_info WHERE user_name=?")) {
mysqli_stmt_bind_param($statement,"s",$login_username);
mysqli_stmt_execute($statement);
$result=mysqli_stmt_get_result($statement);
$num=mysqli_num_rows($result);
}
if($num==1) {
while ($row=mysqli_fetch_assoc($result)) {
$user_name=$row['user_name'];
$enc_user_name=password_hash($user_name,PASSWORD_DEFAULT);
$user_friend=bin2hex(random_bytes(32));
$token=password_hash($user_friend);
$user_signature="$enc_user_name"."___"."$user_friend";
//=====================================================================
if(password_verify($login_password,$row['password'])) {
$_SESSION['user_name']=$user_name;
if(isset($_POST['rememberme'])) {
mysqli_query($dbc,"UPDATE customers_info
SET myenc='$token'
WHERE user_name='$user_name'");
setcookie('cats_love_balls',$user_signature,(time()-3600));
}
header('Location: myfile.php');
}
//===================================================================
}
}
} else {
echo 'not found';
}
}
?>
and here is the mysql statement for creating mytable:
CREATE TABLE `customers_info` (
`user_name` varchar(50) NOT NULL,
`password` varchar(255) DEFAULT NULL,
`first_name` varchar(50) DEFAULT NULL,
`last_name` varchar(50) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`myenc` varchar(300) DEFAULT NULL,
PRIMARY KEY (`user_name`)
);
I do not know if this is important,but i am using Ubuntu 16.04 if you please, I need your help to solve my issue.