473,574 Members | 5,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parse error: syntax error, unexpected '"' in ....

riverdale1567
13 New Member
Hi All
More help required by a newbie, thx in advance...

I am trying to run a query
Expand|Select|Wrap|Line Numbers
  1. $query = 'SELECT * FROM BIZ_APARTMENTS WHERE ((bizState='" . mysql_real_escape_string($_POST['b']) .
  2. "'&&(bizCity='" . mysql_real_escape_string($_POST['c']) . "')';
what is the proper way to format this?
thx again
Jan 18 '10 #1
17 2196
Scooby10
5 New Member
Switch your quotes around...
Jan 18 '10 #2
riverdale1567
13 New Member
First thanks Scooby for your help.
I am trying to post data from 2 different scripts to the query you see below
Expand|Select|Wrap|Line Numbers
  1. $query = 'SELECT * FROM BIZ_APARTMENTS WHERE ((bizState="' . mysql_real_escape_string($_POST['b']) .
  2. '"&&(bizCity="' . mysql_real_escape_string($_POST['c']) . '")';
the post data is coming from 2 different pages.

This one generates a drop down
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /*  Program name: buildSelect.php
  3.  *  Description:  Program builds a selection list
  4.  *                from the database.
  5.  */
  6. ?>
  7. <html>
  8. <head><title>Building info by state</title></head>
  9. <body>
  10. <?php
  11.   $user="XXXXXXXXXXt";
  12.   $host="XXXXXXXXXXXX";
  13.   $password="XXXXXXXXX";
  14.   $database = "XXXXXXXXXXXX";
  15.  
  16.   $cxn = mysqli_connect($host,$user,$password,$database)
  17.          or die ("couldn't connect to server");
  18.   $query = "SELECT DISTINCT bizState FROM BIZ_APARTMENTS ORDER BY bizState";
  19.   $result = mysqli_query($cxn,$query)
  20.             or die ("Couldn't execute query.");
  21.  
  22.  /* create form containing selection list */
  23.   echo "<form action='processform41.php' method='POST'>
  24.         <select name='b'>\n";
  25.  
  26.   while ($row = mysqli_fetch_assoc($result))
  27.   {
  28.      extract($row);
  29.      echo "<option value='$bizState'>$bizState\n";
  30.   }
  31.   echo "</select>\n";
  32.   echo "<input type='submit' value='Select State in which building is located'>
  33.         </form>\n";
  34. ?>
  35. </body></html>
  36.  
and passes the info post [b] to this script
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $username="XXXXXXXXX";
  4. $password="XXXXXXXXXX";
  5. $database="XXXXXXXXXXt";
  6. $table="BIZ_APARTMENTS";
  7. $column="bizState";
  8.  
  9. error_reporting(E_ALL);
  10. mysql_connect("localhost",$username,$password);
  11. @mysql_select_db($database) or die( "Unable to select database");
  12.  
  13.  
  14. $query = "SELECT DISTINCT bizCity FROM BIZ_APARTMENTS WHERE bizState='" . mysql_real_escape_string($_POST['b']) . "'";
  15.  
  16.  
  17. $result=mysql_query($query);
  18. $ret = mysql_query($query) or die(mysql_error());
  19. $num=mysql_numrows($result);
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  echo "<b><center>Cities in State</center></b><br><br>";
  27.  
  28.  /* create form containing selection list */
  29.   echo "<form action='city.php' method='POST'>
  30.         <select name='c'>\n";
  31.  
  32.   $i=0;
  33.   while ($i < $num) {
  34.  
  35.  
  36.   $city=mysql_result($result,$i,"bizCity");
  37.  
  38.  
  39.      echo "<option value='$city'>$city\n";
  40.      $i++;
  41.   }
  42.   echo "</select>\n";
  43.   echo "<input type='submit' value='Select City in which building is located'>
  44.         </form>\n";
  45.  print_r($result);
  46.  
  47.  ?>
  48.  
  49.  
which in turn should pass both post[b] and post[c] to this form for output
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $username="xxxxxxxxxx";
  3. $password="xxxxxxxxxxx";
  4. $database="xxxxxxxxx";
  5. $table="xxxxxxxxx";
  6. $column="bizState";
  7. error_reporting(E_ALL);
  8.  
  9. mysql_connect("localhost",$username,$password);
  10. @mysql_select_db($database) or die( "Unable to select database");
  11.  
  12.  
  13.  
  14.  
  15. $query = 'SELECT * FROM BIZ_APARTMENTS WHERE ((bizState="' . mysql_real_escape_string($_POST['b']) .
  16. '"&&(bizCity="' . mysql_real_escape_string($_POST['c']) . '")';
  17.  
  18.  
  19.  
  20. $result=mysql_query($query);
  21. $ret = mysql_query($query) or die(mysql_error());
  22. $num=mysql_numrows($result);
  23.  
  24.   mysql_close();
  25.  
  26.  
  27.  
  28.  
  29.  echo "<b><center>Buildings in City</center></b><br><br>";
  30.  
  31. $i=0;
  32. while ($i < $num) {
  33. $name=mysql_result($result,$i,"bizName");
  34. $address=mysql_result($result,$i,"bizAddr");
  35. $city=mysql_result($result,$i,"bizCity");
  36. $state=mysql_result($result,$i,"bizState");
  37. $zip=mysql_result($result,$i,"bizZip");
  38. $phone=mysql_result($result,$i,"bizPhone");
  39. $email=mysql_result($result,$i,"bizEmail");
  40.  
  41.  echo "<b>Name: $name</b><br>Phone: $phone<br>Type: $type<br>Address: $address<br>City: $city<br>State: $state<br>Zip: $zip<br>Email:$email<br>";
  42.  
  43. $i++;
  44.  }
  45. print_r($city);
  46.  ?>
  47.  
  48.  
BUT I am getting error message
Notice: Undefined index: b in /home/attorney/public_html/in-url.com/bigdump/city.php on line 15
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
thanks again, the help i have received from this forum has been priceless..
Jan 18 '10 #3
Scooby10
5 New Member
Could it be the && in the query? Try replacing that with AND..
Jan 18 '10 #4
Dormilich
8,658 Recognized Expert Moderator Expert
that’s not it, there’s simply no field named "b" in the last script.
Jan 18 '10 #5
riverdale1567
13 New Member
so how do I transfer data from the field [b] in the first script into the 3rd script so the query in the 3rd script can use fields 'b' and 'c'?
Expand|Select|Wrap|Line Numbers
  1. $query = 'SELECT * FROM BIZ_APARTMENTS WHERE ((bizState="' . mysql_real_escape_string($_POST['b']) .
  2. '"&&(bizCity="' . mysql_real_escape_string($_POST['c']) . '")';
Jan 18 '10 #6
Dormilich
8,658 Recognized Expert Moderator Expert
you could add a hidden field to pass down the b value
Expand|Select|Wrap|Line Numbers
  1. echo '<input type="hidden" name="b" value="' . $_POST["b"] . '">';
Jan 18 '10 #7
riverdale1567
13 New Member
First, let me say thank you again to both of you for you time and effort in helping me.
In my 3rd script, I am still getting the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
this is the script:
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $username="xxxxxxxxxx";
  3. $password="xxxxxxxxx";
  4. $database="xxxxxxxxxx";
  5. $table="BIZ_APARTMENTS";
  6. $column="bizState";
  7.  
  8.  
  9. mysql_connect("localhost",$username,$password);
  10. @mysql_select_db($database) or die( "Unable to select database");
  11.  
  12.  
  13.  
  14.  
  15. $query = 'SELECT * FROM BIZ_APARTMENTS WHERE ((bizState="' . mysql_real_escape_string($_POST['b']) .
  16. '"&&(bizCity="' . mysql_real_escape_string($_POST['c']) . '")';
  17.  
  18.  
  19.  
  20. $result=mysql_query($query);
  21. $ret = mysql_query($query) or die(mysql_error());
  22. $num=mysql_numrows($result);
  23.  
  24.   mysql_close();
  25.  
  26.  
  27.  
  28.  
  29.  echo "<b><center>Buildings in City</center></b><br><br>";
  30.  
  31. $i=0;
  32. while ($i < $num) {
  33. $name=mysql_result($result,$i,"bizName");
  34. $address=mysql_result($result,$i,"bizAddr");
  35. $city=mysql_result($result,$i,"bizCity");
  36. $state=mysql_result($result,$i,"bizState");
  37. $zip=mysql_result($result,$i,"bizZip");
  38. $phone=mysql_result($result,$i,"bizPhone");
  39. $email=mysql_result($result,$i,"bizEmail");
  40.  
  41.  echo "<b>Name: $name</b><br>Phone: $phone<br>Type: $type<br>Address: $address<br>City: $city<br>State: $state<br>Zip: $zip<br>Email:$email<br>";
  42.  
  43. $i++;
  44.  }
  45. print_r($city);
  46.  ?>
  47.  
  48.  
Also I am not getting any output either.

Thank you very much,
Josh
Jan 18 '10 #8
Dormilich
8,658 Recognized Expert Moderator Expert
there are 2 closing parentheses missing in the SQL.
Jan 18 '10 #9
riverdale1567
13 New Member
Dormilich
Dude you are awesome, thanks ever so much. It always amazes when the s*** actually works.
Danke
Jan 18 '10 #10

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

Similar topics

4
2671
by: Marcin Dobrucki | last post by:
I've been having some problems with a parse error that I can't figure out (PHP 4.3.11 on Solaris9). Sample code: <?php // getting strange parse errors on this class A { var $value; function A() { $this->value = 1; }
8
46173
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
22140
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"...
36
7978
by: rhys | last post by:
My Gurus and Angels -- Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My shortcomings will soon become apparent. I am developing an estimating construction system, using PHP5 and MySQL 5.0.24a with Ubuntu. I have a main...
3
6943
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...
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
3521
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...
3
5590
paulrajj
by: paulrajj | last post by:
hi to all, i am getting syntax error on my code.. Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in D:\xampp\htdocs\Dummy\paulraj\matrim\exam.php on line 62 what's the actual problem here..? my code
14
5493
riverdale1567
by: riverdale1567 | last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada. I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up all the rows which have the corresponding state. I am getting this 'Parse error: syntax error, unexpected T_STRING in /home/attorney/public_html/' on...
0
8079
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
8258
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
7833
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...
0
6481
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5635
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
3756
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...
0
3770
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1081
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.