artweb Posted January 15, 2008 Share Posted January 15, 2008 I need a way to record users info into my sql database. I have a php login form that when the user enters their username and password it check to see if the user is in the database if so it takes them to the members only page. But after the user is successfully login I want a way to record the users company name and time spent on the site and the date they login. but I dont have a clue of how to do this. Do I need two tables one for the usernames and passwords and another for recording the user info? or Do I use sessions and cookies some how? My php code that I have so far is posted below. <?php ob_start(); $host="my.mysql.server"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="my_database"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); if($result){ echo "Sorry"; } //mysql_num_row is counting table row $count=mysql_num_rows($result); //if result match $myusername and mypassword table row must be 1 row if($count==1){ session_register("myusername"); header("location:brochures.html"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/86189-solved-new-to-php-and-my-sql-can-anyone-please-help-me/ Share on other sites More sharing options...
neylitalo Posted January 15, 2008 Share Posted January 15, 2008 It's a Really Bad Idea to put your mysql user information in public places. I could've logged in and deleted everything. Quote Link to comment https://forums.phpfreaks.com/topic/86189-solved-new-to-php-and-my-sql-can-anyone-please-help-me/#findComment-440194 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.