PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
The following code displays validating login and password. If true then "member-index.php" is called. I want to insert values in a table called "last-login" but, although the code seems to function properly, nothing gets populated in the "last-logn" table. As always, I appreciate your help.
//Create query
$qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
echo "<span style="color: #BF0000">";
$query="INSERT INTO `Users`.`last_login` (`member_id`, `login_time`, `login_date`, `logout_time`, `logout_date`) VALUES (2, CURTIME(), CURDATE(), \'\', \'\')";
@mysql_query($query);
echo "</span>";
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
session_write_close();
header("location: member-index.php");
exit();
}else {
//Login failed
header("location: login-failed.php");
exit();
}
}else {
die("Query failed");
}
that's assuming you already made your sql connection before all of this. try adding those echo statements and using the @ infront of your mysql_query statement. You could also assign it to a variable eg $run = mysql_query($query); then say if($run) { } else { echo mysql_error(); } that way you can see what error is being given