469,292 Members | 1,312 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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

riverdale1567
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 1918
Switch your quotes around...
Jan 18 '10 #2
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
Could it be the && in the query? Try replacing that with AND..
Jan 18 '10 #4
Dormilich
8,651 Expert Mod 8TB
thatís not it, thereís simply no field named "b" in the last script.
Jan 18 '10 #5
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,651 Expert Mod 8TB
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
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,651 Expert Mod 8TB
there are 2 closing parentheses missing in the SQL.
Jan 18 '10 #9
Dormilich
Dude you are awesome, thanks ever so much. It always amazes when the s*** actually works.
Danke
Jan 18 '10 #10
Dormilich
8,651 Expert Mod 8TB
thinking like a parser helps. and experience.
Jan 18 '10 #11
Sorry about the profanity, it the Bronx in me that just comes out sometimes :-)
Jan 18 '10 #12
Dormilich
8,651 Expert Mod 8TB
thatís why there is an "edit" link.
Jan 18 '10 #13
How many years have you been programming?
Jan 18 '10 #14
Dormilich
8,651 Expert Mod 8TB
started with HTML and JS about 10 years ago and doing PHP for about 5 years. but that’s not much since I do it for a hobby.
Jan 18 '10 #15
I wish I kept up with it all from when I started.
I bought a TRS80 model1 in 1980, I was 13 and started doing BASIC.
The hard drive was a cassette recorder LOL.

Nowadays my motivation is business, and the use of php mysql to generate large dynamic sites for seo/marketing. I have five kids to feed.

Whats the best way (MAYBE THIS SHOULD BE A NEW THREAD) to convert those ugly urls with all those funky characters such as'?' into something much cleaner and seo friendly?
Jan 18 '10 #16
Dormilich
8,651 Expert Mod 8TB
"?" is not a funky character … but yes, that should be asked in another thread.
Jan 18 '10 #17
Atli
5,058 Expert 4TB
@riverdale1567
For Apace servers: mod_rewrite. There have been a few discussion on this here already, but you may want to start by checking this article out.

If you have any questions about this then I would appreciate it if you started a new thread. It's just better that way :)
Jan 18 '10 #18

Post your reply

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

Similar topics

4 posts views Thread by Marcin Dobrucki | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.