473,586 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parse error: syntax error, unexpected $end in...

mideastgirl
65 New Member
I keep getting this error and I cannot figure it out. My curly brackets are closed, and I am using the correct tags for <?php to open and ?> to close my code. Can someone please help me!

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //Connect To Database
  3. $hostname='mideasthonors2.db.4381361.hostedresource.com';
  4. $username='**************';
  5. $password='***********';
  6. $dbname='mideasthonors2';
  7. $usertable='admin_tasks';
  8. $yourfield = 'Name';
  9.  
  10. mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
  11. mysql_select_db($dbname);
  12.  
  13. $query = 'SELECT * FROM $usertable';
  14. $result = mysql_query($query);
  15. if($result) {
  16.     while($row = mysql_fetch_array($result)){
  17.         $name = $row['$yourfield'];
  18.         echo 'Name: '.$name;
  19.  
  20. mysql_select_db("mideasthonors2");
  21.  
  22. $sql="INSERT INTO $usertable (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address)
  23.  
  24. VALUES
  25.  
  26. {$_POST['name']},{$_POST['address 1']},{$_POST['address 2']},{$_POST['city']},{$_POST['state']},{$_POST['zip code']},{$_POST['website']},{$_POST['contact name']},{$_POST['position']},{$_POST['phone number']},{$_POST['email address']};
  27.  
  28. if (!mysql_query($sql,$con))
  29.  
  30.   {
  31.  
  32.   die('Error: ' . mysql_error());
  33.  
  34.   }
  35.  
  36. echo '1 record added';
  37.  
  38. mysql_close($con);
  39.     }
  40. }    
  41. ?>
Jun 23 '09 #1
68 11094
Atli
5,058 Recognized Expert Expert
Hi.

You don't close your string properly on line #26.
That's why you get this error.

Also, to close a huge security hole in that code.
Don't put user input directly into SQL queries... or anything, for that matter.
Always validate it and sanitize it before using it.
The mysql_real_esca pe_query function is extremely helpful here.

Check out SQL Injection in the manual. Explains why this is so important.
Jun 23 '09 #2
mideastgirl
65 New Member
How would I end line 26? I have tried removing the semi-colon and using ) instead of } and I still keep getting the same result. I am not really sure what to try next.
Jun 23 '09 #3
Atli
5,058 Recognized Expert Expert
Close the string with a double-quote before the semi-colon.

The string should be enclosed in quote-marks, but you only ever open the string, forgetting to close it with the second quote-mark.

The problem is basically:
Expand|Select|Wrap|Line Numbers
  1. // You are doing this:
  2. $sql = "INSERT INTO whatever;
  3.  
  4. // Where you should be doing
  5. $sql = "INSERT INTO whatever";
  6.  
The variables, which you correctly enclose in brackets, are not a part of the problem, and should work fine if left alone as they are.
Jun 24 '09 #4
mideastgirl
65 New Member
Now it is telling me the brackets are wrong on line 26. The issue the whole time has been with line 26, however I did go ahead and make the changes you suggested:
Expand|Select|Wrap|Line Numbers
  1. mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
  2. mysql_select_db($dbname);
  3.  
  4. $query = 'SELECT * FROM $usertable';
  5. $result = mysql_query($query);
  6. if($result) {
  7.     while($row = mysql_fetch_array($result)){
  8.         $name = $row['$yourfield'];
  9.         echo 'Name: '.$name;
  10.  
  11. mysql_select_db("mideasthonors2");
  12.  
  13. $sql="INSERT INTO $usertable (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address)";
  14.  
  15. VALUES
  16.  
  17. {$_POST['name']},{$_POST['address 1']},{$_POST['address 2']},{$_POST['city']},{$_POST['state']},{$_POST['zip code']},{$_POST['website']},{$_POST['contact name']},{$_POST['position']},{$_POST['phone number']},{$_POST['email address']};
  18.  
  19. if (!mysql_query($sql,$con))
  20.  
  21.   {
  22.  
  23.   die('Error: ' . mysql_error());
  24.  
  25.   }
  26.  
  27. echo '1 record added';
  28.  
  29. mysql_close($con);
  30.     }
  31. }    
  32. ?>
Jun 24 '09 #5
Atli
5,058 Recognized Expert Expert
You closed the string in the wrong line.

Everything you want to have inside a string must be enclosed inside the quotes.
You have like 3 lines there that should be inside your string, but you close the string after the first line.

You are doing something like this:
Expand|Select|Wrap|Line Numbers
  1. $str = "This string spans";
  2.         multiple lines and
  3.         should not be closed
  4.         until after the last line;
  5.  
So PHP, having closed the string after the first line, tries to parse the rest of what should be inside the string as PHP code, obviously failing.

It should look like:
Expand|Select|Wrap|Line Numbers
  1. $str = "This string spans
  2.         multiple lines and
  3.         should not be closed
  4.         until after the last line";
  5.  
Jun 24 '09 #6
mideastgirl
65 New Member
So I put the quote at the end of line 26, which solved that problem. Now at the bottom of the script where the last 2 curly brackets are, I am now receiving this error:

syntax error, unexpected '}' in /home/content/m/i/d/mideasthonors/html/admintaskstable .php on line 23

I thought these brackets were necessary to close the connection?
Jun 24 '09 #7
dlite922
1,584 Recognized Expert Top Contributor
@mideastgirl
It's not that hard. All opened brackets must have closing brackets.

Try this code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
  4. mysql_select_db($dbname);
  5.  
  6. $query = 'SELECT * FROM $usertable';
  7. $result = mysql_query($query);
  8.  
  9. if($result) 
  10. {
  11.     while($row = mysql_fetch_array($result))
  12.     {
  13.         $name = $row['$yourfield'];
  14.         echo 'Name: '.$name;
  15.  
  16.         mysql_select_db("mideasthonors2");
  17.  
  18.         $sql="INSERT INTO $usertable (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address) VALUES {$_POST['name']},{$_POST['address 1']},{$_POST['address 2']},{$_POST['city']},{$_POST['state']},{$_POST['zip code']},{$_POST['website']},{$_POST['contact name']},{$_POST['position']},{$_POST['phone number']},{$_POST['email address']}";
  19.  
  20.         if (!mysql_query($sql,$con))         
  21.         {
  22.             die('Error: ' . mysql_error());
  23.         }
  24.  
  25.         echo '1 record added'; 
  26.     }
  27. }
  28.  
  29. mysql_close($con);    // should be at the same level as your connect(). 
  30.  
  31.  
  32.  
Jun 24 '09 #8
mideastgirl
65 New Member
I tried the code you gave me and this is the error I received:

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/content/m/i/d/mideasthonors/html/admintaskstable .php on line 28

You did not include the database connection which I added on line 2, which gave me an error that no connection was possible, or something to that degree. And now it is giving me the error above. This is the code I am using:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include ("admintasks-dbcon.php");
  3. mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
  4. mysql_select_db($dbname);
  5.  
  6. $query = 'SELECT * FROM $usertable';
  7. $result = mysql_query($query);
  8.  
  9. if($result) 
  10.  {
  11.      while($row = mysql_fetch_array($result))
  12.      {
  13.          $name = $row['$yourfield'];
  14.          echo 'Name: '.$name;
  15.  
  16.          mysql_select_db("mideasthonors2");
  17.  
  18.          $sql="INSERT INTO $usertable (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address) VALUES {$_POST['name']},{$_POST['address 1']},{$_POST['address 2']},{$_POST['city']},{$_POST['state']},{$_POST['zip code']},{$_POST['website']},{$_POST['contact name']},{$_POST['position']},{$_POST['phone number']},{$_POST['email address']}";
  19.  
  20.          if (!mysql_query($sql,$con))         
  21.          {
  22.              die('Error: ' . mysql_error());
  23.          }
  24.  
  25.         echo '1 record added'; 
  26.      }
  27.  }
  28. mysql_close($con); 
  29. ?>
Jun 24 '09 #9
code green
1,726 Recognized Expert Top Contributor
I find it hard to believe you do not understand.
The error message tells you exactly what is wrong.
Expand|Select|Wrap|Line Numbers
  1. mysql_close($con);  
Where is the resource $con?
Is it in
include ("admintasks-dbcon.php");
If not then it just comes randomly into play half way through your script.
Even so it is not a critical error so it should still work.
I would have expected a more serious error earlier because the mysterious $con
is used here
Expand|Select|Wrap|Line Numbers
  1.  if (!mysql_query($sql,$con))    
but php is good at guessing which database you mean
Jun 25 '09 #10

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

Similar topics

1
2278
by: Janwillem Borleffs | last post by:
Q: I'm getting an unexpected $ or $end parse/syntax error, what's causing this? A: This is caused when an expression is started with an opening brace, but the closing brace is omitted. Examples: if ($condition) { .... // No closing brace; the error is thrown
8
46174
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 where the inital " started? I find myself adding /* */ blocks or cutting/pasting sections of code out in order to find where the error occured. ...
4
2193
mikeinspain
by: mikeinspain | last post by:
Keep getting this error! Parse error: syntax error, unexpected $end in /home/9144/domains/cbweb.co.uk/html/faq_finance.php on line 139 PHP Below.. Script was working 1 minute and copied the script from another file that was working great. elseif (!trim($name)) { echo "<p>Ooops!, it appears that you did not enter a Name</p><p><a...
4
22141
kestrel
by: kestrel | last post by:
I have some html code that is supposed to be displayed by php echo. But for some reason i keep getting a syntax error, and i cant figure out what is going on. Heres what i have <?php if(isset($_GET)) { echo "<div id="visible">"; echo "<span onclick="swapform()">Log In Form</span>"; echo "</div>"; echo "<div id="theform"...
5
10018
praclarush
by: praclarush | last post by:
I've just started php, and this is a class assignment, but my question is Iím getting this error PHP Parse error: syntax error, unexpected T_IF, expecting T_VARIABLE or '$' in C:\wamp\www\ssp\SSP04\guessingGame.php on line 42. Iíve tried to make sense of it but Iím at a lose, there error is referring to this segment of the code. else{...
9
4026
by: ajd335 | last post by:
Hi all... I am getting an error Parse error: syntax error, unexpected $end in http:/..... on line 117...(117 is the EOF).. can you plz help me out..I have checked out for the < , > ,{ ,} etc.... I donno where m wrong.... <?php class S_Shipping { // Private variables.
2
3211
by: Lawrence Krubner | last post by:
Imagine a template system that works by getting a file, as a string, and then putting it through eval(), something like this: $formAsString = $controller->command("readFileAndReturnString", $formName); // 06-22-07 - the next commands try to import all the functions that the
2
3234
by: fburn | last post by:
I need some help with an error I'm getting using php 5.2.5 running on linux. I receive an error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/inventoryControl/supplier.php on line 26 (line number changed to match code tags) The code is as follows: ...
9
3522
akohistani
by: akohistani | last post by:
I am having Parse error problem with my newly purchased Php upload script I have uploaded the script and I get the error below Parse error: syntax error, unexpected $end in URL/functions.php on line 400 Someone please help me I contacted the owner of the script where I purchased he is not replying me I bought it from...
10
5639
by: benicio | last post by:
Parse error: syntax error, unexpected T_STRING, expecting '(' in C:\wamp\www\study_group\includes\functions.php on line 19 I got this error and this syntax is from 8 to 19th line. <?php $subject_set = get_all_subjects(); while ($subject = mysql_fetch_array($subject_set)) { echo...
0
7841
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8204
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8339
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7965
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5712
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 presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3838
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
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 we have to send another system
0
1184
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.