I want to find the users firstname. HOW DO I DO THIS? All I have is their email.
How do I find the corresponding firstname? I’ve tried many ways, but I still can’t find it. I AM A NOOB. I am trying a login, but can’t figure this out.
Here is my code.
[php]<?php
session_start();
$con = mysql_connect(“localhost”,“user”);
if(!$con) {
die(‘Error connecting to localhost’ . mysql_error());
}
$db = mysql_select_db(“socialdb”,$con);
if(!$db) {
die(‘Error connecting to database’ . mysql_error());
}
$email = $_POST[‘email’];
$password = $_POST[‘password’];
$hashedPassword = hash(“sha512”, $password);
$checke = mysql_query(“SELECT * FROM persons WHERE email=’$email’”);
if(mysql_num_rows($checke)<1) {
header(‘Location: wrong-login.php’);
exit();
}
$checkp = mysql_query(“SELECT * FROM persons WHERE password=’$hashedPassword’”);
if(mysql_num_rows($checkp)<1) {
header(‘Location: wrong-login.php’);
exit();
}
$sql = “SELECT Firstname, Lastname FROM persons WHERE
email = '”.$_POST[“email”]."’ AND
Password = ‘".$hashedPassword."’";
$result = mysql_query($sql, $con) or die(mysql_error($con));
if (mysql_num_rows($result) == 1) {
while ($info = mysql_fetch_array($result)){
$Fname = $info[‘firstname’];
$Lname = $info[‘lastname’];
}
$_SESSION[‘firstname’] = $Fname;
$_SESSION[‘lastname’] = $Lname;
}
mysql_close($con);
?>[/php]
I took out the MySQL username in here.
And here is the error I’m getting (actually two)
Notice: Undefined index: firstname in C:\wamp\www\login2.php on line 40
Notice: Undefined index: lastname in C:\wamp\www\login2.php on line 41
Thanks!