Couple of things,
1 - you need to add session_start(); to the very top of the page (before any html)
2 - You need to change if (isset($_POST[‘username’])) { to if (isset($_POST[‘submit’])) { on that first page and on the hell page, get rid of it completely.
3 - for any of the php to work, you need to either remove the action, or move the processing code to the page indicated in the action.
4 - you can not have any text being printed to the screen (echo, print, etc) before a header call, you’ll get a butt load of headers already sent error messsages.
5 - if the action is removed, then you need to name your submit button.
login page
[php]session_start(); // has to be at the very top of the page
if (isset($_POST[‘submit’])) {
$username = $_POST[‘username’];
$password = $_POST[‘password’];
$sql = mysql_query("SELECT * FROM student WHERE username='$username' AND password='$password'") or die mysql_error());
if (mysql_num_rows($slq) == 1 ) {
$row = mysql_fetch_assoc($sql);
$_SESSION['fname'] = $row['fname']; // change to match your first name column
header("Location: sad52/studentpage.php");
}else {
echo"invalid username or password.";
exit();
}
}
?>[/php]
You’re already selecting all the information for that user, there’s no reason to request the same information. I could see it if you were just asking for 1 column in the first query, but you’re not. And since you’re getting the information, why not use it.
ok, again. in your form tag, you have action=“student.php”. that tells the form to send the information in the form to that page. IF the php you have posted is on that page, then you’re good, BUT if its not, then nothing will happen. Since the code appears to be on the same page, then just change the action to action="".
[u][i]Notice: Undefined variable: slq in C:\xampp\htdocs\student.php on line 19
Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\student.php on line 19
invalid username or password.[/i][/u]
but the username and password I inputted are correct.