473,499 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

following code is giving a parse error,syntax error,$end error

1 New Member
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. include("includes/config_db.php");
  4.  // Define $myusername and $mypassword
  5. $myusername=$_POST['myusername'];
  6. $mypassword=$_POST['mypassword'];
  7.  
  8. // To protect MySQL injection (more detail about MySQL injection)
  9. $myusername = stripslashes($myusername);
  10. $mypassword = stripslashes($mypassword);
  11. $myusername = mysql_real_escape_string($myusername);
  12. $mypassword = mysql_real_escape_string($mypassword);
  13.  
  14. $sql="SELECT * FROM members WHERE username='$myusername' and password=password('$mypassword')";
  15. $result=mysql_query($sql);
  16.  
  17. // Mysql_num_row is counting table row
  18. $count=mysql_num_rows($result);
  19. // If result matched $myusername and $mypassword, table row must be 1 row
  20.  
  21. if($count==1){
  22. // Register $myusername, $mypassword and redirect to file "login_success.php"
  23. $_SESSION['myusername'] = $myusername;
  24. $_SESSION['mypassword'] = $mypassword;
  25. //session_register("myusername");
  26. //session_register("mypassword");
  27. header("location:login_success.php");
  28. }
  29. else {
  30. ?>
  31. <table align="center" width="100%" border="0" cellpadding="0" cellspacing="1">
  32. <tr><td align="center"><br/><br/>
  33. <?
  34. echo "Wrong Username or Password";
  35. echo "<br/><input type=\"button\" name=\"Back\" value=\"Back\"  onclick=\"javascript: history.go(-1)\" />";
  36. ?>
  37. </td></tr></table>
  38. <?
  39. }
  40.  
  41. ob_end_flush();
  42. ?>
Apr 13 '14 #1
5 1495
Luuk
1,047 Recognized Expert Top Contributor
- where are the line numbers you are getting your errors on?
- why did you not use the '[code]' tags to post your code?

- you should not use the short tag '<?', always use the long one '<php'
Apr 13 '14 #2
Dormilich
8,658 Recognized Expert Moderator Expert
an $end error typically is caused by brace mismatch.
Apr 15 '14 #3
datingstory
2 New Member
What is "?>" used for at line 30, 33, 36 and 38?
Apr 16 '14 #4
Dormilich
8,658 Recognized Expert Moderator Expert
context change between PHP and HTML.
Apr 16 '14 #5
koharu
10 New Member
Hi Kity.

I've cleaned up the code you posted, please bare in mind that most cases of bad coding are due to messy coding being difficult even for the author to follow.

Here's the cleaned code with comments on improvement. I have verified that the syntax is correct and working.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. include("includes/config_db.php");
  4.  // Define $myusername and $mypassword
  5. $myusername = $_POST['myusername'];
  6. $mypassword = $_POST['mypassword'];
  7.  
  8. // To protect MySQL injection (more detail about MySQL injection)
  9. $myusername = stripslashes($myusername);
  10. $mypassword = stripslashes($mypassword);
  11. $myusername = mysql_real_escape_string($myusername);
  12. $mypassword = mysql_real_escape_string($mypassword);
  13.  
  14. $sql = "SELECT * FROM `members` WHERE `username` = '{$myusername}' and password = password('{$mypassword}')";
  15. $result = mysql_query($sql);
  16.  
  17. // Mysql_num_row is counting table row
  18. //$count = mysql_num_rows($result); //You don't really need this, the MySQL query will return false if no results are found.
  19. // If result matched $myusername and $mypassword, table row must be 1 row
  20.  
  21.     if($result){ //Check to see if $result is true or false.
  22.         // Register $myusername, $mypassword and redirect to file "login_success.php"
  23.         $_SESSION['myusername'] = $myusername;
  24.         $_SESSION['mypassword'] = $mypassword;
  25.         //session_register("myusername");
  26.         //session_register("mypassword");
  27.         header("location:login_success.php");
  28.     }else {
  29.         //Condense the echo statements. You don't have to escape the double quotes, just invert the quotes that Echo uses.
  30.         echo '<table align="center" width="100%" border="0" cellpadding="0" cellspacing="1">
  31. <tr><td align="center"><br/><br/>Wrong Username or Password<br/><input type="button" name="Back" value="Back"  onClick="javascript: history.go(-1)" /></td></tr></table>';
  32.         //Also try to ensure that you reduce the number of times you open or close a PHP tag, they can be rather tricky to follow. It also helps to keep those pesky PHP Parsers where opening and closing php tags is not allowed happy.
  33.     }
  34.  
  35. ob_end_flush();
  36. //    EOF
  37. ?>
May 5 '14 #6

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

Similar topics

8
46158
by: Wescotte | last post by:
The error message Parse error: syntax error, unexpected $end in FILE on line X is one I run into frequently and I know the cause is I missed an ending quote. Is there an easy way to determine...
12
1685
by: Brigitte Smith | last post by:
I'm trying to make an image map and when I click on any part of it now it gives "Parse error: syntax error, unexpected T_VARIABLE in /usr/data2/hosted/angelauset/IMGMAPONE/map.php on line 11" ...
3
2637
by: CYNTHIA CUTRER | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> ...
1
2778
by: Pete Burns | last post by:
Creating a registration form and am getting a parse error on the line in the html form code for email address?! Any thoughts please. // Check for a first name: if (empty($_POST)) {...
2
3086
by: Vicki Hendra | last post by:
Hi I am new to php fullstop I and colleagues have setup wordpress blogs for our local towns, giving the local businesses free advertisment. Part of the problem started when using wordpress...
3
2604
by: Ann Madden | last post by:
Hello - I am super green to php and mysql. I have received the following error: Parse error: syntax error, unexpected $end in C:\website\chart.php on line 84... I have been through the code matching...
9
3119
by: togoode | last post by:
Hello everyone, I'm new to php and to forums so please be gentle. I'm trying to create my first form and php script for a website that will allow the user to send their info to me in an email....
1
5748
by: James Long | last post by:
I am getting the following error: Parse error: syntax error, unexpected $end in E:\wamp\www\forums\view_topic.php on line 138 And i am a newbie.. I have been working on the code for ages and now...
1
2386
by: Jeroendutch | last post by:
Helle everyone, I'm am not that familiar with HTML codes etc. but I do have a serious problem with my website witch gives the following code if I open it: Parse error: syntax error, unexpected...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.