473,378 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Parse error: syntax error, unexpected T_VARIABLE

3
Holla...
i' getting an error in this code :

Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\webdav\OSP_Assignment2\edit promo book.php on line 151

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.    $con = my_sql_connect("localhost", "root", "");
  3.    my_sql_select_db("my_db", $con); 
  4.  
  5.    if(!$_POST['Submit'])
  6.    {
  7.      $sql = "SELECT * FROM 'Promo_Booking' WHERE 'GuestFirstName' = $_GET[GuestFirstName]";
  8.      $result = mysql_query($sql);
  9.      $book = mysql_fetch_array($result);
  10.    }
  11. ?>
  12.  
  13.  
  14.  
  15. <table width="66%" height="100" border="0" align="center">
  16.   <tr>
  17.     <td><div align="center"><font color="#666666" size="+30"><strong>PROMOTION</strong></font></div></td>
  18.   </tr>
  19. </table>
  20. <p></p>
  21.  
  22. <table width="50%" border="1" align="center" cellpadding="5" cellspacing="0">
  23.   <tr>
  24.        <td><p align="center"><strong><font size="4">RESERVATION FORM</font></strong></p>
  25.  
  26. <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  27. <table width="699" border="0" align="center" cellpadding="7" cellspacing="0" cols="1">
  28.    <tr>
  29.         <td width="681">
  30.  
  31. <table bordercolor="#CCCCCC" width="650" border=1 align="center" cellpadding="4" cellspacing="0" cols="1" >
  32.   <tr>
  33.       <td width="669"><strong>1. Guest Details</strong></td>
  34.   </tr>
  35.   <tr>
  36.       <td>
  37.  
  38. <table bordercolor="#CCCCCC" width="644" border="1" align="center" cellpadding="3" cellspacing="0" cols="2">
  39.   <tr>
  40.        <td width="172">Book for:</td><td width="454"><input type="text" name="promo" value="<?php echo $book['promo'];?>"></td>
  41.   </tr>
  42.   <tr>
  43.        <td width="172">Number of adults:</td><td width="454"><input name="adults" type="text" size="2" value="<? echo $book['adults']; ?>"></td>
  44.   </tr>
  45.   <tr>
  46.        <td>Number of childrens:</td><td><input name="child" type="text" size="2" value="<? echo $book['child']; ?>"></td>
  47.   </tr>
  48.   <tr>
  49.         <td>Guest name:</td>
  50.         <td><input name="guestfirstname" type="text" size="25" value="First name" value="<? echo $book['guestfirstname']; ?>">&nbsp;
  51.             <input name="guestlastname" type="text"  size="25" value="Last name" value="<? echo $book['guestlastname']; ?>"></td>
  52.   </tr>
  53. </table>
  54.         </td>
  55.   </tr>
  56. </table> 
  57.         </td>
  58.   </tr>                    
  59.   <tr>
  60.         <td>
  61.  
  62. <table bordercolor="#CCCCCC" width="650" border="1" align="center" cellpadding="3" cellspacing="0" cols="1">
  63. <tr>
  64.      <td width="479"><strong>2. Contact Information</strong></td>
  65. </tr>
  66. <tr>
  67.      <td>
  68.  
  69. <table bordercolor="#CCCCCC" width="645" border="1" align="center" cellpadding="3" cellspacing="0" cols="2">
  70. <tr>
  71.      <td width="150">Email Address:</td>
  72.      <td width="422"><input name="email" type="text" size="25" value="<? echo $book['email']; ?>"></td>
  73. </tr>
  74. <tr>
  75.      <td>Mobile Phone:</td>
  76.      <td><input name="phone" type="text" value=" " size="25" value="<? echo $book['phone']; ?>"></td>
  77. </tr>
  78. <tr>
  79.      <td>Nationality:</td>
  80.      <td><input name="nationality" type="text" value=" " size="25" value="<? echo $book['nationality']; ?>"></td>
  81. </tr>
  82. </table>
  83.         </td>
  84.    </tr>
  85. </table>        
  86.         </td>
  87.    </tr>        
  88.    <tr>
  89.         <td align="center">
  90.  
  91. <table bordercolor="#CCCCCC" width="656" border="1" align="center" cellpadding="3" cellspacing="0" cols="1">
  92.   <tr>
  93.         <td width="646"><strong>3. Credit-Card Details</strong></td>
  94.   </tr>
  95.   <tr>
  96.         <td>
  97.  
  98. <table bordercolor="#CCCCCC" width="645" border="1" align="center" cellpadding="3" cellspacing="0" cols="2">
  99.   <tr>
  100.         <td width="155">Credit card type</td>
  101.         <td width="417"><input type="text" name="creditcardselect" size="25" value="<? echo $book['creditcardselect']; ?>"></td>
  102.   </tr>
  103.   <tr>
  104.         <td>Name on card:</td><td><input name="cardname" type="text" size="25" value="<? echo $book['cardname']; ?>"></td>
  105.   </tr>
  106.   <tr>
  107.         <td>Card number:</td><td><input name="cardnumber" type="text" size="25" value="<? echo $book['cardnumber']; ?>"></td>
  108.   </tr>
  109.   <tr>
  110.         <td>Security code:</td><td><input name="securitycode" type="text" size="10" value="<? echo $book['securitycode']; ?>"></td>
  111.   </tr>
  112.   <tr>
  113.         <td>Expiry date:</td>
  114.         <td><input name="expirydate" value="<? echo $book['expirydate']; ?>">/&nbsp;
  115.             <input name="expiryyear" value="<? echo $book['expiryyear']; ?>">
  116.         </td>
  117.   </tr>
  118.   <tr>
  119.         <td>Issuing bank:</td><td><input name="issuingbank" type="text" size="25" value="<? echo $book['issuingbank']; ?>"></td>
  120.   </tr>
  121.   <tr>
  122.         <td>Service phone:</td><td><input name="servicephone" type="text" size="25" value="<? echo $book['servicephone']; ?>"></td>
  123.   </tr>
  124.   <tr>
  125.         <td>Billing Adress:</td>
  126.         <td><input name="billingaddress" type="text" size="25" value="<? echo $book['billingaddress']; ?>"></td>
  127.   </tr>
  128.   <tr>
  129.         <td>City:</td><td><input name="city" type="text" size="25" value="<? echo $book['city']; ?>"></td>
  130.   </tr>
  131. </table>
  132.         </td>
  133.   </tr>
  134. </table>
  135.             <br> <input name="Submit" type="submit" value="Submit">
  136.             <br> <input name="Submit" type="submit" value="Edit">
  137.         </td>
  138.   </tr>
  139. </table>
  140. </form>
  141.  
  142.  
  143.  
  144.     </td>
  145.   </tr>
  146. </table>              
  147.  
  148.  
  149. <?php
  150.      if(isset($_POST['Submit'])){
  151.      $sql = "UPDATE Promo_Booking SET 'GuestFirstName' = "$_POST[guestfirstname]", 'GuestLastName' = "$_POST[guestlastname]",
  152.             'Promo' = "$_POST[promo]", 'NumberOfAdults' = "$_POST[adults]", 'NumberOfChildren' = "$_POST[child]",
  153.             'EmailAddress' = "$_POST[email]", 'MobilePhone' = "$_POST[phone]", 'Nationality' = "$_POST[nationality]",
  154.             'CreditCardType' = "$_POST[creditcardselect]", 'NameOnCard' = "$_POST[cardname]", 'CardNumber' = "$_POST[cardnumber]",
  155.             'SecurityCode' = "$_POST[securitycode]", 'ExpiryDate' = "$_POST[expirydate]", 'ExpiryYear' = "$_POST[expiryyear]",
  156.             'Issuingbank' = "$_POST[issuingbank]", 'ServicePhone' = "$_POST[servicephone]",
  157.             'BillingAddress' = "$_POST[billingaddress]", 'City' = "$_POST[city]" WHERE GuestFirstName = $_POST[guestfirstname]"; 
  158.  
  159.     mysql_query($sql) or die(mysql_error());
  160.     echo "Your Reservation has been updated!";
  161.     header("Location : promo booking form3.php");
  162. ?>
  163.  
Apr 8 '10 #1
6 2000
code green
1,726 Expert 1GB
Tidy up the quotes in the query
Apr 8 '10 #2
qila
3
is it like this??

Expand|Select|Wrap|Line Numbers
  1.       <?php
  2.      if(isset($_POST['Submit'])){
  3.      $sql = "UPDATE Promo_Booking SET GuestFirstName = "$_POST[guestfirstname]", GuestLastName = "$_POST[guestlastname]",
  4.             Promo = "$_POST[promo]", NumberOfAdults = "$_POST[adults]", NumberOfChildren = "$_POST[child]",
  5.             EmailAddress = "$_POST[email]", MobilePhone = "$_POST[phone]", Nationality = "$_POST[nationality]",
  6.             CreditCardType = "$_POST[creditcardselect]", NameOnCard = "$_POST[cardname]", CardNumber = "$_POST[cardnumber]",
  7.             SecurityCode = "$_POST[securitycode]", ExpiryDate = "$_POST[expirydate]", ExpiryYear = "$_POST[expiryyear]",
  8.             Issuingbank = "$_POST[issuingbank]", ServicePhone = "$_POST[servicephone]",
  9.             BillingAddress = "$_POST[billingaddress]", City = "$_POST[city]" WHERE GuestFirstName = $_POST[guestfirstname]"; 
  10.  
  11.     mysql_query($sql) or die(mysql_error());
  12.     echo "Your Reservation has been updated!";
  13.     header("Location : promo booking form3.php");
  14. ?>
  15.  
Apr 8 '10 #3
code green
1,726 Expert 1GB
You have multiple quotes in the same string which is gibberish.
Wrap the whole string in double quotes and values inside with single quotes.

Before you do that extract the $_POST array into variables.
Apr 8 '10 #4
qila
3
ermmm..
how??
can u xplain it to me..
i'm very new to learn about this.....
Apr 8 '10 #5
code green
1,726 Expert 1GB
OK. Study the string variable
Expand|Select|Wrap|Line Numbers
  1. $sql = "UPDATE Promo_Booking SET GuestFirstName = "$_POST[guestfirstname]", 
  2. GuestLastName = "$_POST[guestlastname]", .....
The string is opened with double quotes; fine, but then closes at the next double quote GuestFirstName = " <<<<.
As far as the parser is concerned, this string has now finished but there is no semi-colon to close the line or a dot to concatenate the string so an error is thrown.
You need $_POST[guestfirstname] wrapped in single quotes, but guestfirstname also needs to be in single quotes because it is an array key. (I think leaving the array key quotes of only produces a notice)
All array elements inside a string need braces {} to be parsed.
So string should be
Expand|Select|Wrap|Line Numbers
  1. $sql = "UPDATE Promo_Booking 
  2. SET GuestFirstName = '{$_POST['guestfirstname']}', 
  3. GuestLastName = '{$_POST['guestlastname']}', .....
But entering $_POST data into a database without validation is bad practice, so always read and validate $_POST array into variables
Expand|Select|Wrap|Line Numbers
  1. $guestfirst = mysql_real_escape_string(striptags($_POST['guestfirstname']));
  2. $sql = "UPDATE Promo_Booking 
  3. SET GuestFirstName = $guestfirst .....
Apr 8 '10 #6
Atli
5,058 Expert 4TB
To reinforce code green's point about the quotes:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // This is how we fetch data from a form or the URL.
  3. $data = mysql_real_escape_string($_POST['data']);
  4.  
  5. // And this is how it is put into a string:
  6. $str = "The data is: {$data}";
  7.  
  8. // If it is supposed to be quoted inside the string
  9. // you need to do either:
  10. $str = "The data is: \"{$data}\".";
  11. // Or:
  12. $str = 'The data is: "' . $data . '".';
  13.  
  14. // It should NOT be like your strings are:
  15. $str = "The data is "$data".";
  16. // This causes your error.
  17. // (How is PHP supposed to know which quote is a
  18. //  part of the string and which quote closes the string?)
  19. ?>

You need $_POST[guestfirstname] wrapped in single quotes, but guestfirstname also needs to be in single quotes because it is an array key. (I think leaving the array key quotes of only produces a notice)
This is true, except for one case. To make it easier to use arrays inside strings, you are allowed to omit the quote marks when using an array inside a string (without the curly-brackets).
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $array = array("hello" => "world");
  3.  
  4. // This is OK
  5. $str = "Hello: $array[hello]";
  6.  
  7. // But this produces the notice
  8. $world = $array[hello];
  9. ?>
However, this is generally considered to be a bad thing to do. The method is very limited and causes problems when dealing with more complex arrays. You are better of using the curly-bracket method you were talking about
Expand|Select|Wrap|Line Numbers
  1. $str = "Hello: {$array['hello']}";
Apr 8 '10 #7

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

Similar topics

6
by: Ehartwig | last post by:
I recently created a script for user verification, solved my emailing issues, and then re-created the script in order to work well with the new PHP 5 that I installed on my server. After...
2
by: aamer | last post by:
can anyone please help me, im getting a dumb: Parse error: syntax error, unexpected T_VARIABLE in /home/jeddah/public_html/lomar/cart/remove.php on line 5 in the following file, <?php...
4
by: bovanshi | last post by:
got this annoying error I'm completly new to php... and i have no clue what is wrong here, from what i can tell there is nothing rong with this code... but that isn't what the borwser say :P ...
5
by: Anna MZ | last post by:
I am new to php and have written the following mysql code to enter the details of a new user in the admin subdomain of my website: $sql = "INSERT INTO 'users' ('userid', 'username', 'upassword')...
1
epots9
by: epots9 | last post by:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/xxx.php on line xxx I get that message when i try to run my...
1
by: mdouble | last post by:
I'm a complete novice with HTML and PHP. Recently I purchased an auto responder that requires me to edit a PHP file during the installation process as per directions provided in a read me file. ...
3
by: SilvaZodiac | last post by:
Hi everyone, I'm still rather new to PHP code, and I have a syntax error. I've tried several different solutions, but it won't fix. It seems to suggest that I need a new bracket somewhere in the...
4
by: needhelp08 | last post by:
I am getting the error Parse error: syntax error, unexpected T_VARIABLE on line 4 but I can't seem to find what is wrong. Could someone please help. <?php $conn = @mysql_connect("localhost",...
5
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...
2
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.