PHP Login System help please
Hi guys!
I got a problem with my logging in system. I can connect to my database with the code:
session_start();
include('header.html');
$page_title = 'Home Page';
$mail = $_POST['email'];
$password = $_POST['password'];
$msg ='';
if(isset($mail,$password)){
$con = mysql_connect('127.0.0.1','root','');
if(!$con)
{
die('Could not connect: '.mysql_error());
}
else{
echo "Connected!";
}
}
$db_found = mysql_select_db("dbusers", $con);
Then I connect to the table and I want to retrieve the registered users details from the table "mytable" and then I want to greet the registered user with by his name.
$myMail = stripslashes($mail);
$mypassword = stripslashes($password);
$sql ="SELECT * FROM mytable WHERE Email = '$myMail' AND Password='$mypassword'";
$result = mysql_query($sql);
$sql2 ="SELECT Name FROM mytable WHERE Email = '$myMail' AND Password='$mypassword'";
$name = mysql_query($sql2);
No I run through the "array" to find the name according to the email and password
while($rows = mysql_fetch_row($result)){
if($rows['Name'] == $name ){
echo "<h1>Welcome $name </h1>";
}
else{
echo "No Name";
}
}
But the error states:
Notice: Undefined index: Name in C:\Program Files\EasyPHP-5.3.8.1\www\Login.php on line 46
Ok I understand it but the in my table in columns name is "Name" correctly spelled.
Its prob just something small...just need a fresh mind to help me :D
Sorry for the long post.
Kind Regards
Philip
Phillamon
Junior Poster in Training
65 posts since Oct 2010
Reputation Points: 36
Solved Threads: 5
Ok one thing I changed in the while loop the
while($rows = mysql_fetch_row($result)){
TO
while($rows = mysql_fetch_array($result)){
so the error is gone but still I can't retrieve the name of the database/table :/ it just gives me "No Name"
Phillamon
Junior Poster in Training
65 posts since Oct 2010
Reputation Points: 36
Solved Threads: 5
My connection works to my database! It prints the "Connected" string so that is fine...this is not the problem
I can't retrieve the data from the table...although the connection is made and correctly spelled
Phillamon
Junior Poster in Training
65 posts since Oct 2010
Reputation Points: 36
Solved Threads: 5
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
why use a loop to find the user info? why not just grab that specific user's data from the table in the first query
$result=mysql_query("SELECT * FROM mytable WHERE
Email = '".mysql_real_escape_string($myMail)."' AND
Password='".mysql_real_escape_string($mypassword)."'") or die(mysql_error());
if (mysql_num_rows($result)==0){echo "user not found";}
else{
$user=mysql_fetch_assoc($result);
echo $user['Name'];
}
Thank you!It works!!Didn't really know about the mysql_fetch_assoc function but sweet! And so you learn!
@evstevemd - I checked it out-and it's definitely what I was looking for-just a lot of video's though- I'm capped with my BW :/ but non the less Thanks
Phillamon
Junior Poster in Training
65 posts since Oct 2010
Reputation Points: 36
Solved Threads: 5