PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've made a log in code and I've now altered it to refresh you back to the index. So that you're shown as logged in.
Problem I'm having is with displaying the users ID. If I use $_SESSION['id'] it throws up a fuss saying its not recognised 'Undefined index: id'
If I use $_POST['txtid'], I dont get an error until after logging in and refreshing back to the index, saying the same thing 'Undefined index: txtid'. They're only notices but is there a way so that I don't get a notice even notices mean untidy coding.
function validatelogin($id,$password){
// Connect to the database
include("connection.php");
// Build an SQL statment that will return a record with a
// matching id and password.
$sql = "select username, password from userdetails where username='$id' and password= md5('$password');";
$loginresult = mysql_query($sql,$conn);
$userdetails = mysql_fetch_array($loginresult);
// If the SQL query contains a record
if ($userdetails['username']){
$_SESSION['id'] = $id;
return true;
}
else {
$_SESSION['id'] ='';
return false;
}
}
session_start();
include("validate.php");
include("connection.php");
if ($_SESSION['id'] != '' or validatelogin($_POST['txtid'],$_POST['txtpwd']) == true){
echo "<head><meta HTTP-EQUIV='REFRESH' content='0; url=index.php'></head>";
}
else
{
echo "You have posted incorrect log in data you will automatically be redirected";
echo "<head><meta HTTP-EQUIV='REFRESH' content='10; url=index.php'></head>";
}
But you asked where i was setting the session ID so I thought you wanted the code for that function sorry
Well thats what the code does do. I'm not saying it doesnt work, it works but there is a NOTICE: before logging in and I don't want it there. Which means something must not be right.
If you don't have them turned on you wont see it. Obviously... lol - so can someone tell me how to get rid of the notice? (preferably without having to just turn off notices. I'd rather alter my code )