I have this code that will check if the username and the password matched with those inside the database and that would grant the user access to my website.
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="bfp6"; // Database name
$tbl_name="station"; // Table name
// Connect to server and select database.
mysql_connect("localhost", "root", "")or die("cannot connect");
mysql_select_db("bfp6")or die("cannot select DB");
// username and password sent from form
$mystations=$_POST['mystations'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection
$mystations = stripslashes($mystations);
$mypassword = stripslashes($mypassword);
$mystations = mysql_real_escape_string($mystations);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE stations='$mystations' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $mystations, $mypassword and redirect to file "login_success.php"
session_register("mystations");
session_register("mypassword");
header("location:main.html");
}
else {
echo "Wrong Username or Password";
}
?>
But i am really having a hard time because i don't have any idea how to insert to a new database the usernames of those who logged in in my website.I want to insert that code to this one. I have this new table named "log" with fields "id","user","time". What i want to happen is that whenever a person successfully logs in to my website, his/her username will be inserted to the table "log".Maybe with the use of $_POST but i want to make sure that the access is granted. I also already have a code that will display the contents of the table "log: if there is any.Another problem is how would the time automatically insert to the database depending on what time the user logs in. Guys, please help me. My thesis deadline is on feb 16:(