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;
?>
rpkamp
August 12, 2011, 10:16am
2
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>
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…
rpkamp
August 12, 2011, 10:32am
4
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’ "
rpkamp
August 12, 2011, 10:48am
6
Well, there you go
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
rpkamp
August 12, 2011, 11:59am
8
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…
rpkamp
August 12, 2011, 12:45pm
10
Could you post the code you have now please?