0

I'm a newb, so thanks in advance for bearing with me. That being said, I'm trying to update a table in my database and failing. I received a few NULL responses, adjusted a few things, and most recently got a few 500 internal server errors, which typically seem to be related to invalid PHP... any help is greatly appreciated.

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

if ($_POST['room']) {

$room_current = $conn->query('SELECT `Room_Availability` FROM Room_Status WHERE `Room_Name` = "'.$_POST['room'].'"');

if (!$room_current) {
    die('ERROR: '.$conn->error);
}

$room_current = $room_current->fetch_assoc();

if ($room_current['Room_Availability'] == `OUT`); {
    $room_set = $conn->query('UPDATE `Room_Status` SET `Room_Availability`= `IN` WHERE `Room_Name` = "'.$_POST['room'].'"');

    if (!$room_set); {
        die('ERROR: '.$conn->error);
    }
}

var_dump($room_set);

?>

2 Answers2

3

This is your UPDATE:

UPDATE `Room_Status`
    SET `Room_Availability` = `IN`
    WHERE `Room_Name` = "'.$_POST['room'].'"'

The backticks around IN mean that this is a column reference. You probably want a string, so use single quotes:

UPDATE `Room_Status`
    SET `Room_Availability` = 'IN'
    WHERE `Room_Name` = "'.$_POST['room'].'"'
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

just replace the

$room_set = $conn->query('UPDATE `Room_Status` SET
`Room_Availability`= `IN` WHERE `Room_Name` = "'.$_POST['room'].'"');

to

$room_set = $conn->query('UPDATE `Room_Status` SET
`Room_Availability`= 'IN' WHERE `Room_Name` = "'.$_POST['room'].'"');
Pradyut Manna
  • 588
  • 1
  • 3
  • 12
  • Hey guys, thanks so much. I've made those adjustments and I'm still getting an error. The console suggests that other errors exist in a separate PHP file, so now that I have corrected this issue and I can work on from here. Ty again! I'm teaching myself and that information about the backticks was totally new to me and incredibly useful. – user6931612 Oct 06 '16 at 12:02