By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

I've got a "Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\php\vali"

P: 3
hi im new to php and i want to code a admin login page where i want to match the values from the login form with the values of the database table.....when i run the login page after entering the user name and the password i've got a Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\php\validate.php on line 16. Can anybody please help me to slove this matter.

validate.php
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. session_start();
  3. $username= $_POST['adminusername'];
  4. $password= $_POST['adminpass'];
  5.  
  6. $conn= mysql_connect('localhost','root','');
  7. mysql_select_db('onlinestore',$conn);
  8.  
  9. $query='SELECT * FROM admin WHERE adminusername='$username' and adminpassword='$password'';
  10. $result=mysql_query($query);
  11. if(mysql_num_rows($result)==1)
  12. {
  13. header("location:menu.php");
  14. exit();
  15. }
  16. header("location:adminlogin.php");
  17. exit();
  18. ?>
  19. </body>
Jun 3 '10 #1
Share this Question
Share on Google+
5 Replies


Dormilich
Expert Mod 5K+
P: 8,639
wrap your query in double quotes. single quoted strings are not parsed and in your case cause the error.
Jun 3 '10 #2

P: 3
Hey thanks but when i wrap it with double quotes it should go to the menu.php when giving correct username & password right???? but it act as an incorrect input........can u help me???
Jun 3 '10 #3

Dormilich
Expert Mod 5K+
P: 8,639
what does the corrected code look like?
Jun 3 '10 #4

P: 3
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  
  3. $username= $_POST['adminusername'];
  4. $password= $_POST['adminpass'];
  5.  
  6. $conn= mysql_connect('localhost','root','');
  7. mysql_select_db('onlinestore',$conn);
  8.  
  9. $query="SELECT * FROM `admin` WHERE adminusername='$username' and adminpassword='$adminpass';
  10. $result=mysql_query($query);
  11. if(mysql_num_rows($result)==1)
  12. {
  13. header("location:menu.php");
  14. exit();
  15. }
  16. header("location:adminlogin.php");
  17. exit();
  18. ?>
now it says "Parse error: syntax error, unexpected T_STRING in C:\wamp\www\php\validate.php on line 20"
which is ,header("location:menu.php");
Jun 3 '10 #5

Dormilich
Expert Mod 5K+
P: 8,639
if you open a string, you should also close it (i.e. missing closing string delimiter).
Jun 3 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.