php login form...

Jacob

New member
...help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<!<!<!<!!!!!!!!!!!!!!!!!!!!!!!!!!!? i am currently working on a php login form for my website and i am having an error that says

Notice: Use of undefined constant sql - assumed 'sql' in C:\wamp\www\register improved02\index.php on line 62
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sql' at line 1

and my coding so far is

<?php

mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("RegisterForm04") or die(mysql_error());


if(@$_SESSION['uid']) {

echo "You are already logged in!<br>\n";

} else {

?>

<form method="POST" action="index.php">
<table border="0" style="font-size: 15px; font-family: Tahoma; border: 1px solid black;">
<tr>
<td>
Username:
</td>
<td>
<input type="text" name="username" value="<?php echo @$_POST['username']; ?>">
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="password" name="password" value="<?php echo @$_POST['password']; ?>">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="Login">
</td>
</tr>
</table>
</form>

<?php


if(@$_POST['submit']) {

$curnum = 0;

$username = $_POST['username'];
$password = $_POST['password'];

if(!$username) {
$curnum ++;
echo $curnum . ". You need to enter a username!<br>\n";
}

if(!$password) {
$curnum ++;
echo $curnum . ". You need to enter a password!<br>\n";
}

$sql ="SELECT * FROM users WHERE username='".$username."'";
$res = mysql_query(sql) or die(mysql_error());

if ($username) {
if(mysql_num_rows($res) == 0) {
$curnum ++;
echo $curnum . ". The username '<b>".$username."</b>' does not exist!<br>\n";
}
}

}






}

?>



also if it helps any i am using notepad ++
 
Read your compiler error message!

Basically it's complaining you have an undefined variable on line 62, which is this line:

$res = mysql_query(sql) or die(mysql_error());

There's something wrong with that line, namely you're missing the $ in front of sql. It should be $sql, not sql.
 
Back
Top