kaiman Posted December 15, 2010 Share Posted December 15, 2010 Hi again everyone, I am trying to compare a php variable to the value of a row in mysql, but keep getting the following error: Wrong perameter count for mysql_result() What syntax would I use to accomplish this? Here is my code: // connects to server and selects database. include ("../includes/dbconnect.inc.php"); // table name $table_name = "availability"; // split up date into 3 separate fields $date = "12/25/2010"; $date_split = explode("/", $date); $month = $date_split[0]; $day = $date_split[1]; $year = $date_split[2]; // check if earth room is already reserved $taken = "Reserved"; $sql = "SELECT earth_room FROM $table_name WHERE month='$month' AND day='$day' AND year='$year' LIMIT 1"; $result = mysql_query($sql) or trigger_error("A mysql error has occurred!"); $row = mysql_result($result); if($row == $taken){ echo "Room Already Reserved"; } else{ echo "Room Available"; } Thanks for the help, kaiman Quote Link to comment https://forums.phpfreaks.com/topic/221701-compare-mysql-row-value-to-php-variable/ Share on other sites More sharing options...
MMDE Posted December 15, 2010 Share Posted December 15, 2010 look up the mysql_result function, and you will see that it requires you to specify row too and alternatively a field, not just a mysql query result. ( http://php.net/manual/en/function.mysql-result.php) You should try to use mysql_fetch_array instead! Quote Link to comment https://forums.phpfreaks.com/topic/221701-compare-mysql-row-value-to-php-variable/#findComment-1147470 Share on other sites More sharing options...
BK87 Posted December 15, 2010 Share Posted December 15, 2010 <? $row=mysql_fectch_array($result); if($row["earth_room"]==$taken){ //do something } ?> Quote Link to comment https://forums.phpfreaks.com/topic/221701-compare-mysql-row-value-to-php-variable/#findComment-1147471 Share on other sites More sharing options...
trq Posted December 15, 2010 Share Posted December 15, 2010 You don't actually need to compare any values, you should write your check into your query. $sql = "SELECT earth_room FROM $table_name WHERE month='$month' AND day='$day' AND year='$year' AND earth_room = 'Reserved' LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { echo "Room Already Reserved"; } else { echo "Room Available"; } } else { trigger_error("A useless error message!"); } Quote Link to comment https://forums.phpfreaks.com/topic/221701-compare-mysql-row-value-to-php-variable/#findComment-1147476 Share on other sites More sharing options...
kaiman Posted December 15, 2010 Author Share Posted December 15, 2010 @MMDE Ah, yes I see, thanks for pointing that out. @ BK87 Thanks mysql_fetch_array worked. @ thorpe Okay, thanks for the alternative method... Sarcasm on the mysql error noted. I tend to use error logs to review problems instead. This is really what the message should say: trigger_error("A useless error message displayed to hackers who want to learn the directory paths on the server!"); Problem solved, kaiman Quote Link to comment https://forums.phpfreaks.com/topic/221701-compare-mysql-row-value-to-php-variable/#findComment-1147480 Share on other sites More sharing options...
trq Posted December 15, 2010 Share Posted December 15, 2010 Better still. trigger_error(mysql_error() . "<br />$sql"); Then all you need do is enable display errors on your development server and disable them on production. Quote Link to comment https://forums.phpfreaks.com/topic/221701-compare-mysql-row-value-to-php-variable/#findComment-1147482 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.