Jump to content

simple php error

- - - - -

  • Please log in to reply
6 replies to this topic

#1
ravi951

ravi951

    Newbie

  • Members
  • PipPip
  • 18 posts
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\newlogin.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;
?>

Edited by Orjan, 12 August 2011 - 03:56 AM.
changed to php tags for highlighting


#2
Zero_Cool

Zero_Cool

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
line 8 first code you didnt closed the row
$sqlstt="select * from users where uid='$uname' and pwd='$pwd';
$sqlstt="select * from users where uid='$uname' and pwd='$pwd'";


#3
ravi951

ravi951

    Newbie

  • Members
  • PipPip
  • 18 posts
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\newlogin.php on line 10"
and even i gave correct username and password.
it is displaying as invalid....
what would be the problem...

#4
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
Can you do a var_dump($uname) and var_dump($pwd) just before $sqlstt

#5
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
a sugestion is to use an editor with syntax highlighting so you easily can see these errors.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#6
Zero_Cool

Zero_Cool

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
you dont have a connection to the db thats why you recive the error as you mentioned you need to put the variable that holds the connection to your db
$sqlstt="select * from users where uid='$uname' and pwd='$pwd',$var of connection to db";


#7
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
The connection variable isn't needed unless you handle several open connections. And if you wanted it, it should not go in the end of the query, but as a parameter to mysql_query() function. The error can be several things: No open connection, wrong database selected, non-existing table or not enough rights. The easiest is to print out the eventual error codes upon a query like this

$stmt = "select * from users where uid='$uname' and pwd='$pwd'";
mysql_query($stmt) or die ("Query: ". $stmt ." made error ".mysql_errno().": ".mysql_error());

This gives information about many different kinds of errors.
A, it outputs the query with all variables filled in, and therefore you can read the query and see if you wrote something wrong.
B, it shows eventual errors from the server so you know where to look for the error.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users