Simple php error

hi all,
i am getting error on the following php program.it is displaying the error as “Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs
ewlogin.php on line 12”
not getting what is the problem with it…
below is my login.php code…


<?php
if(isset($_POST['sub']))
{
mysql_connect("localhost","root","");
mysql_select_db("test");
$uname=$_POST['txtuname'];
$pwd=$_POST['txtpwd'];
$sqlstt="select * from users where uid='$uname' and pwd='$pwd';
$data=mysql_query($sqlstt);
if(mysql_num_rows($data)==1)
{
header("Location:welcome.php?un=$uname");
}
else
{
echo "invalid";
}
}
?>
<form method="post" action="">
username:<input type='text' name='txtuser'>
<br>
password:<input type='text' name='txtpwd'>
<br>
<input type='submit' name='sub' value='login'>
</form>

also is the welcome.php


<?php
$user=$_REQUEST['un'];
echo "welcome to ".$user;
?>

Look at it with color highlighting, I’m sure you’ll see the problem:


<?php
if(isset($_POST['sub']))
{
mysql_connect("localhost","root","");
mysql_select_db("test");
$uname=$_POST['txtuname'];
$pwd=$_POST['txtpwd'];
$sqlstt="select * from users where uid='$uname' and pwd='$pwd';
$data=mysql_query($sqlstt);
if(mysql_num_rows($data)==1)
{
header("Location:welcome.php?un=$uname");
}
else
{
echo "invalid";
}
}
?>
<form method="post" action="">
username:<input type='text' name='txtuser'>
<br>
password:<input type='text' name='txtpwd'>
<br>
<input type='submit' name='sub' value='login'>
</form>

:slight_smile:

You forgot the close the string on line 8 with a " . It should be $sqlstt="select * from users where uid='$uname' and pwd='$pwd'";

i have corrected the error above error.but now it is showing the error as
“Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs
ewlogin.php on line 10”
and even i gave correct username and password.
it is displaying as invalid…
what would be the problem…

Change


$data=mysql_query($sqlstt);

to


$data=mysql_query($sqlstt) or die ('Error in query: '.mysql_error());

and run the script again. Do you get an error?

the error is showing as
"Error in query:Unknown column ‘uid’ in ‘where clause’ "

Well, there you go :slight_smile:

Now just find out what the correct field name is, and change the query.
(I can’t help you there, because I can’t see your database)

“users” is my table name which contains two fields username and password.
i gave values correctly …then also showing error

If you your fields are called username and password, why do you use uid and pwd in your query?

Also, I’d change from MySQL to MySQLi, and take a look at the mysqli_real_escape_string function, or prepared statements.

i have changed uid to username and pwd to password in the main program but also showing the same error…

Could you post the code you have now please?