illuz1on Posted May 12, 2007 Share Posted May 12, 2007 if ($result = mysql_query(SELECT * FROM beaches WHERE ocean='mysql_real_escape_string($_GET['action']')); Pls can someone help me fix that line of code.. Thanks Link to comment https://forums.phpfreaks.com/topic/51113-solved-sql-selection-line/ Share on other sites More sharing options...
Barand Posted May 12, 2007 Share Posted May 12, 2007 <?php $action = mysql_real_escape_string($_GET['action']); if ($result = mysql_query("SELECT * FROM beaches WHERE ocean = '$action' ")) { // do something } ?> Link to comment https://forums.phpfreaks.com/topic/51113-solved-sql-selection-line/#findComment-251612 Share on other sites More sharing options...
illuz1on Posted May 12, 2007 Author Share Posted May 12, 2007 ok worse than i thought... getting Parse error: parse error, unexpected '{' in /home/capetown/public_html/dev/beaches.php on line 19 <?php $action = mysql_real_escape_string($_GET['action']); if (isset($_GET["action"])) { if ($result = mysql_query("SELECT * FROM beaches WHERE ocean=$action"); if (mysql_num_rows($result)) { while($row = mysql_fetch_array($result)) { extract($row); echo ""; } } } } else { echo ""; } ?> Link to comment https://forums.phpfreaks.com/topic/51113-solved-sql-selection-line/#findComment-251620 Share on other sites More sharing options...
Barand Posted May 12, 2007 Share Posted May 12, 2007 You put the ; back. if ($result = mysql_query("SELECT * FROM beaches WHERE ocean=$action"); <---- remove, add ) { Link to comment https://forums.phpfreaks.com/topic/51113-solved-sql-selection-line/#findComment-251623 Share on other sites More sharing options...
illuz1on Posted May 12, 2007 Author Share Posted May 12, 2007 Thanks alot - that worked out but again, I have run into another problem: This is the whole pages code, it loads and does everything - but doesnt display the beaches when either Atlantic or Indian is selected - just shows nothing.. <?php /* Created on: 4/23/2007 */ ?> <? include("db.php"); ?> <html> <body> Cape Town Beaches<br> <br> <a href="beaches.php?action=atlantic">Atlantic Ocean</a> | <a href="beaches.php?action=indian">Indian Ocean</a> | <a href="beaches.php?action=all">All Beaches</a><br> <br> Show me the Cape Town Alive guide to a going to the right beach! <a href="beaches.php?action=guide">click here</a><br> <hr> </body> </html> <?php $action = mysql_real_escape_string($_GET['action']); if (isset($_GET["action"])) { if ($result = mysql_query("SELECT * FROM beaches WHERE ocean=$action")) { if (mysql_num_rows($result)) { while($row = mysql_fetch_array($result)) { extract($row); echo "$action <table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td><table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\"> <tr> <td class=\"header\">$name - <img src=\"images/rating$rating.gif\"></td> <td> </td> </tr> <tr> <td colspan=\"2\"><hr></td> </tr> <tr> <td colspan=\"2\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\"> <tr> <td width=\"10%\"><img src=\"images/beaches/$picture.jpg\" width=\"87\" height=\"87\"></td> <td width=\"90%\" valign=\"top\" class=\"content_text\">$sdesc</td> </tr> </table></td> </tr> <tr align=\"right\"> <td colspan=\"2\" class=\"read_more_text\"><hr></td> </tr> <tr align=\"right\"> <td colspan=\"2\" class=\"read_more_text\"><a href=\"morebeach.php?id=$id\">show more information</a> | <a href=\"addshort.php?id=$id\">add to shortlist</a> | <a href=\"gallery.php?id=$id\">gallery</a></td> </tr> </table></td> </tr> </table>"; } } } } else { echo "This is where a nice writeup of the beaches would go!"; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/51113-solved-sql-selection-line/#findComment-251628 Share on other sites More sharing options...
Barand Posted May 12, 2007 Share Posted May 12, 2007 If $action is non-numeric it needs to be in quotes if ($result = mysql_query("SELECT * FROM beaches WHERE ocean = '$action' ")) { Link to comment https://forums.phpfreaks.com/topic/51113-solved-sql-selection-line/#findComment-251631 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.