priest_004 Posted November 24, 2010 Share Posted November 24, 2010 Hi folks, I am a complete n00b at php and mysql. I am teaching myself from books and the WWW, but alas I am stuck... the error I get is: Parse error: syntax error, unexpected T_STRING in X:\xampp\htdocs\search.php on line 7 here is the code: <?php mysql_connect ("localhost", "user", "password") or die (mysql_error()); mysql_select_db ("it_homehelp_test") or die (mysql_error()); $term = $_POST['term']; $sql = $mysql_query(select * from it_homehelp_test where ClientName1 like '%term%'); <<<------this is line 7 while ($row = mysql_fetch_array($sql)){ echo 'Client Name:' .$row['ClientName1']; echo 'Address:' .$row['Address1']; echo 'Phone:' .$row['Tel1']; } ?> Any help you can offer would be great. I can also post the ".html" file that creates the search bar if it is needed. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/219714-parse-error-syntax-error-unexpected-t_string-in-xxampphtdocssearchphp-on/ Share on other sites More sharing options...
Rifts Posted November 24, 2010 Share Posted November 24, 2010 should be $sql = mysql_query("select * from it_homehelp_test where ClientName1 like '%term%' "); Quote Link to comment https://forums.phpfreaks.com/topic/219714-parse-error-syntax-error-unexpected-t_string-in-xxampphtdocssearchphp-on/#findComment-1139034 Share on other sites More sharing options...
ManiacDan Posted November 24, 2010 Share Posted November 24, 2010 Look at your post. See the problem? Get an editor like EclipsePDT that highlights PHP for you, you'll see string errors like this more easily. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/219714-parse-error-syntax-error-unexpected-t_string-in-xxampphtdocssearchphp-on/#findComment-1139039 Share on other sites More sharing options...
priest_004 Posted November 24, 2010 Author Share Posted November 24, 2010 Hi Dan, and Rifts, I see it, I missed the " from the front and end... dough!! thanks for pointing that out. --------------------------------------- ok new problem... now it says... Fatal error: Function name must be a string in X:\xampp\htdocs\search.php on line 7 I thought it was a string. this is starting to hurt my head now... Same line.. ??? what have i missed this time? Quote Link to comment https://forums.phpfreaks.com/topic/219714-parse-error-syntax-error-unexpected-t_string-in-xxampphtdocssearchphp-on/#findComment-1139067 Share on other sites More sharing options...
priest_004 Posted November 24, 2010 Author Share Posted November 24, 2010 Ok folks, I have sorted the FATAL ERROR now it is telling me.. Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in X:\xampp\htdocs\search.php on line 8 I think I might just have to go back to the drawing board for this one.... any clues on this?? code now reads.. <?php mysql_connect ("localhost", "user", "password") or die (mysql_error()); mysql_select_db ("it_homehelp_test") or die (mysql_error()); $term = $_POST['term']; $sql = mysql_query("select * from it_homehelp_test where ClientName1 like '%term%' "); while ($row = mysql_fetch_array($sql)){ echo 'Client Name' .$row['ClientName1']; echo 'Address' .$row['Address1']; echo 'Phone' .$row['Tel1']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/219714-parse-error-syntax-error-unexpected-t_string-in-xxampphtdocssearchphp-on/#findComment-1139073 Share on other sites More sharing options...
ManiacDan Posted November 24, 2010 Share Posted November 24, 2010 Turn error_reporting on, and print mysql_error. mysql_query returns false when there is an error. You are using "false" like a database result object, when clearly it isn't. You're also using the word "term" instead of the variable $term, and you're not running $term through mysql_real_escape_string. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/219714-parse-error-syntax-error-unexpected-t_string-in-xxampphtdocssearchphp-on/#findComment-1139083 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.