Jump to content

compare mysql row value to php variable


kaiman

Recommended Posts

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

Link to comment
Share on other sites

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!");
}

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.