mikebyrne Posted April 1, 2008 Share Posted April 1, 2008 Im trying to code a searchfield in my site but im getting the error: Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\MainPage\login.php on line 138 line 138 is: } else { My code so far is: <table width="100%" cellpadding="0" cellspacing="0" border="0" class="b1sw2" style="background:url(Pictures/searchbox_bg.gif) no-repeat #003;"> <col width="1%"> <col width="99%"> <tr> <td> </td> <td> <label for="searchfield" class="t10nw"></label><br /><br /><br /><br /><br /><br /> <?PHP include("adminconnect.php"); $tbl_name = "product"; $cat = mysql_real_escape_string($_POST['cat']); $input = mysql_real_escape_string($_POST['searchfield']); $query = "SELECT * FROM $tbl_name WHERE $cat LIKE '%$input%'"; $result = mysql_query($result); while($row = mysql_fetch_array && mysql_num_rows($result) > 0) { $product = $row['product']; echo "".$product." was found. "; } else { echo "No search results found"; } ?> <select name="cat" onChange="setAction(this.options[this.selectedIndex].value);"> <option value="cd" selected="selected" >CDs</option> <option value="dvd" >DVDs</option> <option value="game" >Games</option> </select> <form name="ex2" method="get" action="/searchresults_cd.php"> <input type="text" name="searchfield" size="22" maxlength="40" id="srchdrop" /> <input type="submit" value="Search Now! »" id="gosrch" /> </td></tr> </form> </table> Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/ Share on other sites More sharing options...
conker87 Posted April 1, 2008 Share Posted April 1, 2008 You can't have an else after a while. Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506276 Share on other sites More sharing options...
mikebyrne Posted April 1, 2008 Author Share Posted April 1, 2008 How can I get round that?? Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506287 Share on other sites More sharing options...
conker87 Posted April 1, 2008 Share Posted April 1, 2008 try: while($row = mysql_fetch_array) { if *mysql_num_rows($result) > 0) { $product = $row['product']; echo "".$product." was found. "; } else { echo "No search results found"; } } Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506368 Share on other sites More sharing options...
kenrbnsn Posted April 1, 2008 Share Posted April 1, 2008 Do this instead: <?php $result = mysql_query($result); if (mysql_num_rows($result) > 0)) { while($row = mysql_fetch_array) { $product = $row['product']; echo "$product was found<br>"; } } else { echo "No search results found"; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506372 Share on other sites More sharing options...
mikebyrne Posted April 1, 2008 Author Share Posted April 1, 2008 Getting the error Parse error: syntax error, unexpected ')' in C:\xampp\htdocs\MainPage\login.php on line 134 Line 134 is: if (mysql_num_rows($result) > 0)) { Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506398 Share on other sites More sharing options...
dmccabe Posted April 1, 2008 Share Posted April 1, 2008 delete one of the ) after the 0 you have 1 too many Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506403 Share on other sites More sharing options...
mikebyrne Posted April 1, 2008 Author Share Posted April 1, 2008 Thanks! My code now posts to searchresults.php. What needs to be here to display the resuts. Is it just a matter of echoing $product?? Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506417 Share on other sites More sharing options...
conker87 Posted April 1, 2008 Share Posted April 1, 2008 Do this instead: <?php $result = mysql_query($result); if (mysql_num_rows($result) > 0)) { while($row = mysql_fetch_array) { $product = $row['product']; echo "$product was found<br>"; } } else { echo "No search results found"; } ?> Ken Yeah that lol <-- fail Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506525 Share on other sites More sharing options...
AndyB Posted April 1, 2008 Share Posted April 1, 2008 Yeah that lol <-- fail "Fail" is useless to us in terms of helping with your problem. Please describe what happens, why you consider it a failure, what error messages if any are displayed, etc. etc. Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506535 Share on other sites More sharing options...
mikebyrne Posted April 1, 2008 Author Share Posted April 1, 2008 I DIDNT MENTION "FAIL" (its not in my vocab!) lol At present ive coded a serchfield on my login page which should pass the results to searchresults.php. I presume i need to use the $_GET [Result]; I'm just not how to code it to see whats getting passed over Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506541 Share on other sites More sharing options...
conker87 Posted April 1, 2008 Share Posted April 1, 2008 Lol, sorry, I actually meant I failed. As in I failed at that piece of code. Not the code failed. Just to clear that up ^^ Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506557 Share on other sites More sharing options...
mikebyrne Posted April 1, 2008 Author Share Posted April 1, 2008 I know, no problem. Any idea how I can ger $result to show on show on searchresults.php?? Link to comment https://forums.phpfreaks.com/topic/98951-parse-error-syntax-error-unexpected-t_else/#findComment-506569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.