Jump to content

[SOLVED] new to php and my sql can anyone please help me?????


artweb

Recommended Posts

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();

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.