cyprus Posted September 14, 2006 Share Posted September 14, 2006 How can I bypass the code below if my $fields and $where have not been executed yet? The first time the page appears its empty. Thanks $username="root";$password="";$database="";mysql_connect(localhost,$username);$query = "SELECT $fields FROM ORDERS $where";@mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query($query) or die('Problem with query: ' . $query . '<br>'. mysql_error()); $numrows=mysql_numrows($result); Quote Link to comment https://forums.phpfreaks.com/topic/20800-bypass-select-statement-when-empty/ Share on other sites More sharing options...
sford999 Posted September 15, 2006 Share Posted September 15, 2006 You could use an if statement[code]<?php$username="root";$password="";$database="";mysql_connect(localhost,$username);if($fields == "" || $where == ""){// Show the page when nothing is defined for $fields and $where}else{$query = "SELECT $fields FROM ORDERS $where";@mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query($query) or die('Problem with query: ' . $query . ''. mysql_error());$numrows=mysql_numrows($result);}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20800-bypass-select-statement-when-empty/#findComment-92102 Share on other sites More sharing options...
cyprus Posted September 15, 2006 Author Share Posted September 15, 2006 Many many thanks, works a treat. Quote Link to comment https://forums.phpfreaks.com/topic/20800-bypass-select-statement-when-empty/#findComment-92191 Share on other sites More sharing options...
JustinK101 Posted September 15, 2006 Share Posted September 15, 2006 Just curious, what does the @ mean in front of the mysql_select_db() call? Quote Link to comment https://forums.phpfreaks.com/topic/20800-bypass-select-statement-when-empty/#findComment-92193 Share on other sites More sharing options...
markbett Posted September 15, 2006 Share Posted September 15, 2006 surpresses sql errors Quote Link to comment https://forums.phpfreaks.com/topic/20800-bypass-select-statement-when-empty/#findComment-92195 Share on other sites More sharing options...
JustinK101 Posted September 15, 2006 Share Posted September 15, 2006 HUmm, so whats the point if he has the || die(mysql_error()) call. Inst it going to hit the or clause so whats the point of surpressing sql errors? Quote Link to comment https://forums.phpfreaks.com/topic/20800-bypass-select-statement-when-empty/#findComment-92201 Share on other sites More sharing options...
markbett Posted September 15, 2006 Share Posted September 15, 2006 The mysql_select_db( ) function uses the @ to suppress the default error message the ordie that is listed is not well thought out as it returns what you surpressed.... Quote Link to comment https://forums.phpfreaks.com/topic/20800-bypass-select-statement-when-empty/#findComment-92235 Share on other sites More sharing options...
cyprus Posted September 15, 2006 Author Share Posted September 15, 2006 Thanks for the comments on @, I just picked up my colleages line of code. Should I remove @, as I don't want to suppress seing any errors. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/20800-bypass-select-statement-when-empty/#findComment-92250 Share on other sites More sharing options...
Jenk Posted September 15, 2006 Share Posted September 15, 2006 Only very few circumstances warrant the use of the error suppresor. Quote Link to comment https://forums.phpfreaks.com/topic/20800-bypass-select-statement-when-empty/#findComment-92251 Share on other sites More sharing options...
cyprus Posted September 15, 2006 Author Share Posted September 15, 2006 Thanks, I will remove it. Regards Quote Link to comment https://forums.phpfreaks.com/topic/20800-bypass-select-statement-when-empty/#findComment-92268 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.