473,692 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help finding "Parse error: syntax error, unexpected T_STRING"

13 New Member
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.p hp' 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 line 13
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $username="XXXXXXXX";
  3. $password="XXXXXX";
  4. $database="XXXXXXXX";
  7. ini_set('display_errors',1);
  8. error_reporting(E_ALL);
  11. mysql_connect("localhost",$username,$password);
  12. @mysql_select_db($database) or die( "Unable to select database");
  13. $query='SELECT * FROM BIZ_APARTMENTS WHERE $_POST('bizState')';
  14. $result=mysql_query($query);
  16. $num=mysql_numrows($result);
  18. mysql_close();
  20. echo "<b><center>Buildings in State</center></b><br><br>";
  22. $i=0;
  23. while ($i < $num) {
  25. $name=mysql_result($result,$i,"bizName");
  26. $address=mysql_result($result,$i,"bizAddress");
  27. $city=mysql_result($result,$i,"bizCity");
  28. $state=mysql_result($result,$i,"bizState");
  29. $zip=mysql_result($result,$i,"bizZip");
  30. $phone=mysql_result($result,$i,"bizPhone");
  31. $email=mysql_result($result,$i,"bizEmail");
  33. 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>";
  35. $i++;
  36. }
  38. ?>
Thanks a million,
Dec 16 '09 #1
14 5499
8,658 Recognized Expert Moderator Expert
the apostrophe at offset 51 closes the string, after that you have to use the command end (;) or string concatenation operator (.).

and please please secure your SQL against SQL Injection (e.g. by means of mysql_real_esca pe_string())
Dec 16 '09 #2
1,044 Recognized Expert Top Contributor
Line 13 is messed up a lot. Firstly, your query is invalid. It will return results, but not what you think. The WHERE clause requires a condition that each row that you want to select has to meet. If you were to say "WHERE 1", then all rows would be selected. If you were to say "WHERE `id` = 1", then only rows where "`id` = 1" is true would be selected. Conditions are more than just a single variable.

Secondly, you can't have the same type of quotation marks inside of the same type of quotation marks without escaping them (using the "\" character).

Thirdly, arrays do not use parentheses for subscript; they use brackets ("[" and "]").

Fourthly, all data in the $_POST array is user input. Therefore, it is unsafe in its raw form. Cleanse it using mysql_real_esca pe_string().
Dec 16 '09 #3
13 New Member
Hi, first let me say thank you to both of you for helping me, I really appreciate it. I have reworked it a little bit but now no error message, but just a echo of my heading only.
here are the 2 php scripts that are involved. Building Select try it out, plz
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="attorney_test";
  12.   $host="localhost";
  13.   $password="Baronj55";
  14.   $database = "attorney_test";
  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.");
  22.  /* create form containing selection list */
  23.   echo "<form action='processform2.php' method='POST'>
  24.         <select name='b'>\n";
  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>
here is the 2nd script
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $username="attorney_test";
  3. $password="Baronj55";
  4. $database="attorney_test";
  5. $table="BIZ_APARTMENTS";  
  6. $column="bizState";
  7. ini_set('display_errors',1);
  8. error_reporting(E_ALL);
  11. mysql_connect("localhost",$username,$password);
  12. @mysql_select_db($database) or die( "Unable to select database");
  13. $query="SELECT * FROM $table WHERE bizState='$_POST'";
  14. $result=mysql_query($query);
  15. $ret = mysql_query($query) or die(mysql_error());  
  16. $num=mysql_numrows($result);
  18. mysql_real_escape_string($result)
  19.  mysql_close();
  23.  echo "<b><center>Buildings in State</center></b><br><br>";
  25. $i=0;
  26. while ($i < $num) {
  27. $name=mysql_result($result,$i,"bizName");
  28. $address=mysql_result($result,$i,"bizAddress");
  29. $city=mysql_result($result,$i,"bizCity");
  30. $state=mysql_result($result,$i,"bizState");
  31. $zip=mysql_result($result,$i,"bizZip");
  32. $phone=mysql_result($result,$i,"bizPhone");
  33. $email=mysql_result($result,$i,"bizEmail");
  35.  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>";
  37. $i++;
  38.  }
  41.  ?>
thanks again for all the help, having actual human break it down for you is invaluable.
Dec 18 '09 #4
1,044 Recognized Expert Top Contributor
You're going to have to be more clear abt what the error is if you want more help.
Dec 18 '09 #5
13 New Member
Hi Kovik
I am not sure what my error is exactly now, when I go to my first page Building Select and select a state from the drop down. On the following , 'results' page all i get is the page heading and nothing else.
My goal of the 2 scripts is to be able to select a state from the first script then display all the apartment buildings from that state in the second script.
I hope this clarifies.
Thanks a lot, I really appreciate the help.
Dec 18 '09 #6
1,044 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. $query="SELECT * FROM $table WHERE bizState='$_POST'";
You do realize that $_POST is an array, right? print_r() $_POST and see what it gives you. You should know where to go from there.

Also, all data in the $_POST array is user input. As such, you have to cleanse or validate the data. For textual input, mysql_real_esca pe_string() will come in handy.
Dec 18 '09 #7
8,658 Recognized Expert Moderator Expert
you may additionally want to look into PHP Filter Functions.
Dec 18 '09 #8
1,044 Recognized Expert Top Contributor
How long have you been hiding this little treasure from us? o.O
I love PHP. :D
Dec 18 '09 #9
8,658 Recognized Expert Moderator Expert
wait until I rant about Prepared Statements again.
Dec 18 '09 #10

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

Similar topics

by: Steven | last post by:
I got a "Parse error: parse error in ..." in this line: if(empty($_POST){ ..... But if I fist assign $ssn=$_POST; and then if(empty($ssn){ ... it is working. Any advice? Thanks in advance.
by: Andrew E | last post by:
Hi all I've written a python program that adds orders into our order routing simulation system. It works well, and has a syntax along these lines: ./neworder --instrument NOKIA --size 23 --price MARKET --repeats 20 etc However, I'd like to add a mode that will handle, say:
by: | last post by:
Some time ago I installed VC# 2003, made a small generic project, compile with the allow unsafe flag and I get the error below: "error CS1577: Assembly generation failed -- Unexpected exception processing attribute -- System.ArgumentException: Invalid directory on URL." (If I do not compile with the unsafe flag compiler setting all compiles perfect) After long tracing, I ended up discovering that it is csc.exe installed by the .NET...
by: Flip | last post by:
I know the int.Parse("123") will result in an int of 123, but what happens with a null? I believe it give a null exception (seems like I get either NullArgumentException or ArgumentNullException if I'm running it in a console app or in a web app, what's up with that?). I'm trying to get a counter (int) value out of the Application object. When I do the Convert.ToInt32(Application), the first time (it's null), the method converts it to...
by: pinky | last post by:
Hi all I am having one web service where in at a time of calling one webmethod through client application i am continuously getting following error :- The underlying connection was closed: An unexpected error occurred on a
by: jacqueharper | last post by:
I am having a problem with an Excel ListObject in my C# .NET application. I am trying to map an XML schema to a ListObject, and continue to get the error "The XPath is not valid because either the XPath syntax is incorrect or not supported by Excel." No matter what crazy things I try, I can not either get it to work, or get a different, more interesting error message. :-) I have created my ListObject, and added a schema to my XmlMaps. ...
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
by: JToe | last post by:
Hi, I have a sql statement which is as follows:- INSERT INTO expense(Jan) SELECT sum(ECFAmount) FROM Transaction WHERE Date BETWEEN (#01/01/2007#) AND (#01/31/2007# ) When i execute the above, I have an error like this >> java.sql.SQLException: Too few parameters. Expected 1. can someone pls suggest or advise me what can be the problem?
by: ana10192000 | last post by:
VB6.0 Private dbParts as Database Private dbParts as Recordset guys help, i can't execute my program compiler error says: " user-defined type not defined " i'm not much a knowledgable programmer, i'm still just a student, do explain it in a little bit detailed statements. thanks!
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...
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,...
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...
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...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.