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!");
}
?>
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!");
}
?>