473,799 Members | 3,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parse error: syntax error, unexpected T_VARIABLE

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

Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\webdav \OSP_Assignment 2\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 2020
code green
1,726 Recognized Expert Top Contributor
Tidy up the quotes in the query
Apr 8 '10 #2
qila
3 New Member
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 Recognized Expert Top Contributor
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 New Member
ermmm..
how??
can u xplain it to me..
i'm very new to learn about this.....
Apr 8 '10 #5
code green
1,726 Recognized Expert Top Contributor
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 Recognized Expert Expert
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
19031
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 submitting user information into my creation script, I get the following error from the page that is suppose to insert the user data into the database, create a code, then send an email out for verification. Parse error: parse error, unexpected $end in...
2
1952
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 require_once('../include/top.php');?> <? $urlpara_local="clickmenuid=$clickmenuid&smenuid=$smenuid&pageNum_product_rec=$pageNum_product_rec&totalRows_product_rec=$totalRows_product_rec&totrec=$totrec";...
4
11630
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 Parse error: parse error, unexpected T_VARIABLE in main.php on line 15 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title></title>
5
13177
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') VALUES ('$_POST', '$_POST', '$_POST') mysql_query($sql)"; When I view the code in Internet Explorer I get the following error message: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or...
1
2334
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 script, but if i disable an if statement (code below) then my code functions correctly... if($specs == "DT") { $angle = $specs; $rating = $specs; if($angle == "00" || $angle == "30")
1
1408
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. After editing the required file (globals.php) I am directed to run the installation program on the website by using my browser. However, on doing is I am presented with an error message as follows: Parse error: parse error, unexpected...
3
6951
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 offending line, but being amateur, I don't know where. I've tried putting one in several places, to no avail. Clearly, to solve this in a smaller period than a week I need someone with more skill to help out. Heh heh. The error is: Parse error:...
4
4416
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", "root", "password ") $rs1 = @mysql_create_db( $_REQUEST ); $rs2 = @mysql_list_dbs( $conn ); for( $row =0; $row < mysql_num_rows( $rs2 ); $row++ ) { $list .= mysql_tablename( $rs2, $row) ." | "; }
5
10037
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{ if(!isset($_GET)){ echo "<p>****</p>"; $guess = "****"; }//end if //declaring some...
2
3246
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: // get a supplier using the supplier id
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
5463
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4141
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
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.