php - inserting two rows instead of one MySQL using PDO -
i'm trying insert login data login table, , i'm using code:
login.php
$verify = password_verify($password, $results['user_password']); if($verify){ $session->loguser($results['user_id']); header('location: dashboard.php'); }else{ //error }
and in session.php have session class this:
public function loguser($userid){ $_session['userid'] = $userid; $token = $this->createtoken(); $timestamp = time() + (86400 * 14); $connection = new connection; $db = $connection->openconnection(); $stmt = $db->query("insert logins (login_token, login_userid, login_expires) values ('$token', '$userid', '$timestamp')"); $stmt->execute(); }
this working correctly, token being generated, , data correct when check database, it's creating 2 records (identical ones different auto_increment id).
why happening? in advance.
edit: i'm doing token thing in attemp create persistent login, have yet create cookie first wanted test if login data being stored correctly in database.
you executing twice. remove $stmt->execute();
Comments
Post a Comment