Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-30-2006, 09:53 AM   PM User | #1
Webmonkey
New Coder

 
Join Date: Apr 2006
Location: Tadley, UK
Posts: 63
Thanks: 5
Thanked 0 Times in 0 Posts
Webmonkey is an unknown quantity at this point
Help with Mysql Query

Hi,

I am using the script below and i keep getting : No such username . . . and the info the database is there, what could be stopping me? The connect file also works fine.

Thanks

Steven

PHP Code:
<?php

/* ADMIN LOGIN */

echo "<title>Admin Login</title>";
include(
'connect.php');
if (
$_POST['submit']) {
$user $_POST['username'];
$password $_POST['password'];
$mdpass md5($password);
$sql1 mysql_query("SELECT * FROM admins WHERE username = $user");
$r1 = @mysql_num_rows($sql1);
if (
$r1 != 1) {
echo 
"No such username . . .";
die();
} else {
$sql2 mysql_query("SELECT * FROM admins WHERE password = $mdpass AND username = $user");
$r2 = @mysql_num_rows($sql2);
if (
$r2 != 1) {
echo 
"Incorrect Password";
die();
} else {
echo 
"Logged In, Thankyou.";
$_SESSION['logged'] = 1;
echo 
"<a href=\"index.php\">Home</a>";
}
}
} else {
// Form not submit
}

?>
<head>

<style type="text/css">
.text {
font-size:12px;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
</style>
</head><div class="text">
<p>Please use the form below to login to the Admin Control Panel.</p><br />
<form name="login" action="login.php" method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="pass" /><br /><br />
<input type="submit" name="submit" value="Login"><input type="reset" name="reset" />
</form></div>
__________________
Steven Gibbons
klearconcepts@gmail.com

Last edited by Webmonkey; 08-30-2006 at 09:58 AM..
Webmonkey is offline   Reply With Quote
Old 08-30-2006, 10:10 AM   PM User | #2
Webmonkey
New Coder

 
Join Date: Apr 2006
Location: Tadley, UK
Posts: 63
Thanks: 5
Thanked 0 Times in 0 Posts
Webmonkey is an unknown quantity at this point
I've Fixed it using this code:, Its becuase i change if ($res!=1) to is_object($res).

PHP Code:
<?php

/* ADMIN LOGIN */

echo "<title>Admin Login</title>";
include(
'connect.php');
if (
$_POST['submit']) {
$user $_POST['username'];
$password $_POST['password'];
$mdpass md5($password);
$sql1 mysql_query("SELECT * FROM admins WHERE username = $user");
$res = @mysql_num_rows($sql1);
if (
is_object($res)) {
echo 
"$res";
echo 
"No such username . . .";
die();
} else {
$sql2 mysql_query("SELECT * FROM admins WHERE password = $mdpass AND username = $user");
$r2 = @mysql_num_rows($sql2);
if (
is_object($r2)) {
echo 
"Incorrect Password";
die();
} else {
echo 
"Logged In, Thankyou.";
$_SESSION['logged'] = 1;
echo 
"<a href=\"index.php\">Home</a>";
}
}
} else {
// Form not submit
}

?>
<head>

<style type="text/css">
.text {
font-size:12px;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
</style>
</head><div class="text">
<p>Please use the form below to login to the Admin Control Panel.</p><br />
<form name="login" action="login.php" method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="pass" /><br /><br />
<input type="submit" name="submit" value="Login"><input type="reset" name="reset" />
</form></div>
__________________
Steven Gibbons
klearconcepts@gmail.com
Webmonkey is offline   Reply With Quote
Old 08-30-2006, 02:43 PM   PM User | #3
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
You can also just test for true/false as in "if (!$res) {}" (not the C way).
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:09 AM.


Advertisement
Log in to turn off these ads.