cs1h Posted September 11, 2007 Share Posted September 11, 2007 Hi, I'm getting the following error from my php script, Parse error: syntax error, unexpected ')' in D:\Inetpub\vhost\myroho.com\httpdocs\asearching.php on line 10 and the code is <? //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("localhost","adder","clifford"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("real") or die("Unable to select database"); //select which database we're using $keywords = preg_split("/[\s,]+/", trim($_POST['keyword'])); $sql = "SELECT * FROM items WHERE country='" . mysql_real_escape_string($_POST['menuFilesDMA']=) . "' AND type='" . mysql_real_escape_string($_POST['Type']=) . "' AND Abstract LIKE '%" . implode('%', $keyword) . "%'"; } $result = mysql_query($query); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "No results<BR>n"; } else { while($row = mysql_fetch_array($result)) { echo "{$row['somefield']}<BR>n"; } } ?> I'm new to php and I can't find whats wrong with it. Any help would be much appriciated (even if someone can tell me if they think this script will work), Thanks Colin Quote Link to comment https://forums.phpfreaks.com/topic/68822-solved-parse-error/ Share on other sites More sharing options...
MadTechie Posted September 11, 2007 Share Posted September 11, 2007 why do you have the ='s and } ? see comments $sql = "SELECT * FROM items WHERE country='" . mysql_real_escape_string($_POST['menuFilesDMA']=) . "' AND type='" . mysql_real_escape_string($_POST['Type']=) . "' AND Abstract LIKE '%" . implode('%', $keyword) . "%'"; // why the ='s ? } //<-- whats this for ? Quote Link to comment https://forums.phpfreaks.com/topic/68822-solved-parse-error/#findComment-345895 Share on other sites More sharing options...
cs1h Posted September 11, 2007 Author Share Posted September 11, 2007 Thanks for the reply, I removed the } but I am not sure what you mean by the ='s Thanks Colin Quote Link to comment https://forums.phpfreaks.com/topic/68822-solved-parse-error/#findComment-345924 Share on other sites More sharing options...
MadTechie Posted September 11, 2007 Share Posted September 11, 2007 from $sql = "SELECT * FROM items WHERE country='" . mysql_real_escape_string($_POST['menuFilesDMA']=) . "' AND type='" . mysql_real_escape_string($_POST['Type']=) . "' AND Abstract LIKE '%" . implode('%', $keyword) . "%'"; // why the ='s ? to $sql = "SELECT * FROM items WHERE country='" . mysql_real_escape_string($_POST['menuFilesDMA']) . "' AND type='" . mysql_real_escape_string($_POST['Type']) . "' AND Abstract LIKE '%" . implode('%', $keyword) . "%'"; Quote Link to comment https://forums.phpfreaks.com/topic/68822-solved-parse-error/#findComment-345927 Share on other sites More sharing options...
cs1h Posted September 11, 2007 Author Share Posted September 11, 2007 Hi, That new code worked but I am now getting a new error, Warning: implode() [function.implode]: Bad arguments. in D:\Inetpub\vhost\myroho.com\httpdocs\asearching.php on line 10 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Inetpub\vhost\myroho.com\httpdocs\asearching.php on line 13 No results n Any help is much appriciated, Thanks, Colin Quote Link to comment https://forums.phpfreaks.com/topic/68822-solved-parse-error/#findComment-345937 Share on other sites More sharing options...
MadTechie Posted September 11, 2007 Share Posted September 11, 2007 OK what is $keyword ? a string or an array ? do a var_dump($keyword); see what it displays as for the 2nd error change $result = mysql_query($query); to $result = mysql_query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/68822-solved-parse-error/#findComment-345939 Share on other sites More sharing options...
cs1h Posted September 11, 2007 Author Share Posted September 11, 2007 I made the change in the second surgestion and it removed the second error. I think $keyword is a string because it comes from a text box (unless I misunderstand what a string is), I am not sure what you mean by do a var_dump($keyword); Thanks Colin The only message I get now is Warning: implode() [function.implode]: Bad arguments. in D:\Inetpub\vhost\myroho.com\httpdocs\asearching.php on line 10 Quote Link to comment https://forums.phpfreaks.com/topic/68822-solved-parse-error/#findComment-345974 Share on other sites More sharing options...
MadTechie Posted September 11, 2007 Share Posted September 11, 2007 OK if its a string i *think* your trying to do this $sql = "SELECT * FROM items WHERE country='" . mysql_real_escape_string($_POST['menuFilesDMA']) . "' AND type='" . mysql_real_escape_string($_POST['Type']) . "' AND Abstract LIKE '%$keyword%'"; Quote Link to comment https://forums.phpfreaks.com/topic/68822-solved-parse-error/#findComment-345980 Share on other sites More sharing options...
cs1h Posted September 11, 2007 Author Share Posted September 11, 2007 Thanks for all your help MadTechie, it seems to be working now. Cheers Colin Quote Link to comment https://forums.phpfreaks.com/topic/68822-solved-parse-error/#findComment-346004 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.