GPCoin Posted March 19, 2011 Share Posted March 19, 2011 I need some help with a php code I made for a search engine which I will use on my site, but an error code comes up please help me im ok at php but i need some pointers on my code! CODE: <?php $button = $GET_['submit']; $search = $GET_['search']; if (!$button) echo "Please enter a keyword!"; else { if (strlen($search)<2) echo "search term to short" else { echo "you searched for $search <hr size='1'>" } mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_seanhall","81834567"); mysql_select_db("seanhall_search"); $search_exploded = explode(" ",$search) foreach($search_exploded as $search_each) { $x++; if ($x==1) $construct .= "keywords LIKE '%$search_each%'"; else $construct .= " OR keywords LIKE '%$search_each%'"; } $construct = "SELECT * FROM searchengine WHERE $construct"; echo $construct; $run = mysql_query($construct); $found = mysql_num_rows($run) if ($found==0) echo "No results Found."; else { echo "$foundnum results found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { $title = $runrows['title']; $desc = $runrows['description']; $url = $runrows['url'] echo " <b>$title</b><br> $desc<br> <a herf='$url'>$url</a><br> "; } } } ?> error: Parse error: syntax error, unexpected T_ELSE, expecting ',' or ';' in /home/seanhall/public_html/search.php on line 11 Help Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/ Share on other sites More sharing options...
Pikachu2000 Posted March 19, 2011 Share Posted March 19, 2011 When posting code, please enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189636 Share on other sites More sharing options...
GPCoin Posted March 19, 2011 Author Share Posted March 19, 2011 Soz i forgot to add it Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189637 Share on other sites More sharing options...
QuickOldCar Posted March 19, 2011 Share Posted March 19, 2011 change this: $search_exploded = explode(" ",$search) to this: $search_exploded = explode(" ",$search); Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189647 Share on other sites More sharing options...
QuickOldCar Posted March 19, 2011 Share Posted March 19, 2011 actually you forgot the ; in many of the echo's go through them all and add them where missing. Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189649 Share on other sites More sharing options...
QuickOldCar Posted March 19, 2011 Share Posted March 19, 2011 You had a lot of brackets missing and also semicolons, try this and double check your brackets as how to group your else. <?php $button = $GET_['submit']; $search = $GET_['search']; if (!$button) { echo "Please enter a keyword!"; } else { if (strlen($search)<2){ echo "search term to short"; } else { echo "you searched for $search <hr size='1'>"; } mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_seanhall","81834567"); mysql_select_db("seanhall_search"); $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { $x++; if ($x==1) { $construct .= "keywords LIKE '%$search_each%'"; } else { $construct .= " OR keywords LIKE '%$search_each%'"; } $construct = "SELECT * FROM searchengine WHERE $construct"; echo $construct; $run = mysql_query($construct); $found = mysql_num_rows($run); if ($found==0) { echo "No results Found."; } else { echo "$foundnum results found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { $title = $runrows['title']; $desc = $runrows['description']; $url = $runrows['url']; echo " <b>$title</b><br> $desc<br> <a herf='$url'>$url</a><br> "; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189651 Share on other sites More sharing options...
GPCoin Posted March 19, 2011 Author Share Posted March 19, 2011 I tryed the code you posted it worked bit a new error came up: Parse error: syntax error, unexpected $end in /home/seanhall/public_html/search.php on line 66 Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189655 Share on other sites More sharing options...
QuickOldCar Posted March 19, 2011 Share Posted March 19, 2011 Prob need to add extra } at the end. Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189656 Share on other sites More sharing options...
GPCoin Posted March 19, 2011 Author Share Posted March 19, 2011 well it works but once again a new error but now when you enter anything it says "please enter a keyword" even thougth i have, can you see anything which will cause it to KEEP doing it. <?php $button = $GET_['submit']; $search = $GET_['search']; if (!$button) { echo "Please enter a keyword!"; } else { if (strlen($search)<2){ echo "search term to short"; } else { echo "you searched for $search <hr size='1'>"; } mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_seanhall","*********"); mysql_select_db("seanhall_search"); $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { $x++; if ($x==1) { $construct .= "keywords LIKE '%$search_each%'"; } else { $construct .= " OR keywords LIKE '%$search_each%'"; } $construct = "SELECT * FROM searchengine WHERE $construct"; echo $construct; $run = mysql_query($construct); $found = mysql_num_rows($run); if ($found==0) { echo "No results Found."; } else { echo "$foundnum results found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { $title = $runrows['title']; $desc = $runrows['description']; $url = $runrows['url']; echo " <b>$title</b><br> $desc<br> <a herf='$url'>$url</a><br> "; } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189661 Share on other sites More sharing options...
Pikachu2000 Posted March 19, 2011 Share Posted March 19, 2011 When posting code, please enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189666 Share on other sites More sharing options...
QuickOldCar Posted March 19, 2011 Share Posted March 19, 2011 Are you sure button has a value? try to echo button and see the result, maybe is not coming through to the form. Or can try if (!isset($button)) { Maybe even if ($button == "") { Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189668 Share on other sites More sharing options...
GPCoin Posted March 19, 2011 Author Share Posted March 19, 2011 not to be a pain but can you put it in this code because I don't know how to echo a button. sorry. code: <form action="search.php" method="get" > <front face='sans-serif' size=5> <center> Search Engine<br /> <input name="textfield" type="text" id="textfield" size="40" /> <input type='submit' name='search' value='submit'> <center> <font> </form> Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189671 Share on other sites More sharing options...
QuickOldCar Posted March 19, 2011 Share Posted March 19, 2011 All you really need to do is use the one and not the button. <?php $search = $GET_['search']; if (!isset($search)) { echo "Please enter a keyword!"; } else { if (strlen($search)<2){ echo "search term to short"; } else { echo "you searched for $search <hr size='1'>"; } mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_seanhall","*********"); mysql_select_db("seanhall_search"); $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { $x++; if ($x==1) { $construct .= "keywords LIKE '%$search_each%'"; } else { $construct .= " OR keywords LIKE '%$search_each%'"; } $construct = "SELECT * FROM searchengine WHERE $construct"; echo $construct; $run = mysql_query($construct); $found = mysql_num_rows($run); if ($found==0) { echo "No results Found."; } else { echo "$foundnum results found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { $title = $runrows['title']; $desc = $runrows['description']; $url = $runrows['url']; echo " <b>$title</b><br> $desc<br> <a herf='$url'>$url</a><br> "; } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189689 Share on other sites More sharing options...
GPCoin Posted March 19, 2011 Author Share Posted March 19, 2011 I am trying it now. Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189690 Share on other sites More sharing options...
GPCoin Posted March 19, 2011 Author Share Posted March 19, 2011 i used your code and eddited it down and i think i have got it working with one slight hitch here is the error: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'seanhall_seanhal'@'free.monkeyserve.com' (using password: YES) in /home/seanhall/public_html/search.php on line 8 Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'seanhall'@'localhost' (using password: NO) in /home/seanhall/public_html/search.php on line 10 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/seanhall/public_html/search.php on line 10 SELECT * FROM searchengine WHERE keywords LIKE '%%' Warning: mysql_query() [function.mysql-query]: Access denied for user 'seanhall'@'localhost' (using password: NO) in /home/seanhall/public_html/search.php on line 23 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/seanhall/public_html/search.php on line 23 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/seanhall/public_html/search.php on line 24 would this be caused by the lack of $search = $button_['submit']; or beause ive done this with the code: <?php $search = $GET_['search']; echo "you searched for $search <hr size='1'>"; mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_seanhall","********"); mysql_select_db("seanhall_search"); $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { $x++; if ($x==1) { $construct .= "keywords LIKE '%$search_each%'"; } else { $construct .= " OR keywords LIKE '%$search_each%'"; } $construct = "SELECT * FROM searchengine WHERE $construct"; echo $construct; $run = mysql_query($construct); $found = mysql_num_rows($run); if ($found==0) { echo "No results Found."; } else { echo "$foundnum results found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { $title = $runrows['title']; $desc = $runrows['description']; $url = $runrows['url']; echo " <b>$title</b><br> $desc<br> <a herf='$url'>$url</a><br> "; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189696 Share on other sites More sharing options...
QuickOldCar Posted March 19, 2011 Share Posted March 19, 2011 double check your database location and your login parameters to be sure they are correct Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189704 Share on other sites More sharing options...
GPCoin Posted March 19, 2011 Author Share Posted March 19, 2011 omg im just going round in circles, it's now just saying "please enter a keyword". Please can you check over it at http://www.gpcoin.monkeyserve.com/ Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189713 Share on other sites More sharing options...
QuickOldCar Posted March 19, 2011 Share Posted March 19, 2011 ahh, i see now textfield=funny&search=search you have 2 gets, so rename textfield to search and just use that in your form try this <form action="search.php" method="get"> <font face='sans-serif' size=5> <center> Search Engine<br /> <input type="text" name="search" id="search" size="40"/> <input type="submit" /> <center> </font> </form> Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189716 Share on other sites More sharing options...
GPCoin Posted March 19, 2011 Author Share Posted March 19, 2011 ive done that but it still happens http://www.gpcoin.monkeyserve.com/search.php?textfield=test&search=search Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189722 Share on other sites More sharing options...
QuickOldCar Posted March 19, 2011 Share Posted March 19, 2011 ok back to basics, try this link and do a search, then will see the results would show same page and everything works as it should. The code displays after the search is submitted. http://get.blogdns.com/sample-search.php Here's the code for it anyway. <form action="" method="get"> Search: <input type="text" name="search" /> <input type="submit" value="Search"/> </form> <?php $search = mysql_real_escape_string($_GET['search']); if (!isset($search) OR $search == "") { echo "Enter a search word"; } else { echo "<h2>$search</h2>"; } echo "<br />"; ?> This line targets results same page as script <form action="" method="get"> otherwise you can do to target the different page <form action="search.php" method="get"> Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189730 Share on other sites More sharing options...
GPCoin Posted March 19, 2011 Author Share Posted March 19, 2011 what am i sopposed to do with it? Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189736 Share on other sites More sharing options...
QuickOldCar Posted March 20, 2011 Share Posted March 20, 2011 I saw you had this http://www.gpcoin.monkeyserve.com/search.php?textfield=test&search=search so in your form you have the get value as textfield, but in your code you are looking for get values of search. so use the example of the form i gave in that code and try it What I'm saying is you never had any values for $_GET['search'] because your form never sends any Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189740 Share on other sites More sharing options...
GPCoin Posted March 20, 2011 Author Share Posted March 20, 2011 OMG, FFS, it's happended again: "Please enter a keyword" but i think the get is working because of the link: http://gpcoin.monkeyserve.com/search.php?search=test+test Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189746 Share on other sites More sharing options...
QuickOldCar Posted March 20, 2011 Share Posted March 20, 2011 do me a favor and post both the form and the current code remember to wrap them in code tags...lol Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189747 Share on other sites More sharing options...
GPCoin Posted March 20, 2011 Author Share Posted March 20, 2011 ok, here are the codes search form: <div id="apDiv3"> <form action="search.php" method="get"> Search: <input type="text" name="search" /> <input type="submit" value="Search"/> </form> </iframe> </div> Search <?php $search = $GET_['search']; if (!isset($search)) { echo "Please enter a keyword!"; } else { if (strlen($search)<2){ echo "search term to short"; } else { echo "you searched for $search <hr size='1'>"; } mysql_connect("ftp.gpcoin.monkeyserve.com","seanhall_search","*******"); mysql_select_db("seanhall_search"); $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { $x++; if ($x==1) { $construct .= "keywords LIKE '%$search_each%'"; } else { $construct .= " OR keywords LIKE '%$search_each%'"; } $construct = "SELECT * FROM searchengine WHERE $construct"; echo $construct; $run = mysql_query($construct); $found = mysql_num_rows($run); if ($found==0) { echo "No results Found."; } else { echo "$foundnum results found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { $title = $runrows['title']; $desc = $runrows['description']; $url = $runrows['url']; echo " <b>$title</b><br> $desc<br> <a herf='$url'>$url</a><br> "; } } } } ?> I hope you can fix it. Quote Link to comment https://forums.phpfreaks.com/topic/231118-search-engine-code-php-i-need-help/#findComment-1189750 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.