468,321 Members | 1,674 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

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 1644
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

Post your reply

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

Similar topics

6 posts views Thread by Ehartwig | last post: by
1 post views Thread by mdouble | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.