View Full Version : PHP Login Form help

03-17-2009, 07:58 AM
ok, im new to php and im do a fun website to help learn php. Im trying to make my first php site with an account type system, and i have the form working and it will go to the profile page when i enter a username and password, the trouble is i can enter anything... and it will still go to the profile.

What i want it to do is to login with the correct username and password and if the username and password is wrong i want it to redirect to my error.php page with and echo of Login Failed

Can anyone Help?

heres the code i have i have written along with a youtube tutorial

$user = $_POST['user'];
$pass = $_POST['pass'];

if ($user&&$pass)
$connect = mysql_connect("", "leftblank","leftblank") or die ("Couldn't Connect!");
mysql_select_db("nxc") or die ("Couldnt find db");

$query = mysql_query("SELECT * FROM nxc WHERE username='$user'");

$numrows = mysql_num_rows($query);


while (mysql_fetch_assoc($query));

$dbusername = $row['user'];
$dbpassword = $row['pass'];


echo ("Login Successful");

else echo ("Login Failed");
else die("That user doesnt exist!");
else die("Please enter a Username and a Password!");

03-17-2009, 10:12 AM

if your


you currently dont actually do anything except for echoing a message.
If you add

header( 'Location: error.php' )

to an error-branch, then this page will be displayed.

03-17-2009, 06:29 PM
ok so where would i place that header code? and it will go to the error page if the password is wrong? and to the profile if its correct?

sorry still pretty new at php, started two days ago.