...

View Full Version : PHP Login Form help



MasterGraphics
03-17-2009, 06: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


<?php
if(isset($_POST['user']))
{
$user = $_POST['user'];
$pass = $_POST['pass'];

if ($user&&$pass)
{
$connect = mysql_connect("66.7.207.100", "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);

if($numrows!=0)
{

while (mysql_fetch_assoc($query));
{

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

}

if($user==$dbusername&&$pass==$dbpassword)
{
echo ("Login Successful");

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

NoJ
03-17-2009, 09:12 AM
MasterGraphics,

if your


if($user==$dbusername&&$pass==$dbpassword)

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.

MasterGraphics
03-17-2009, 05: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum