Sjaakarie
Sjaakarie

Reputation: 17

How can i determine status an do stuff in PHP MySQL

I try to determine the status of a record is 0 or 1.

I would like to use this code seen below to determine if a specific item in this case barcode='D189404954' is onstock or not, if so do stuff else do nothing.

But when i run the code below it keeps saying the status is 1 even when its 0.

<?php

$link = mysqli_connect("localhost", "root", "", "watermeter");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

$query = "SELECT statuswm
FROM users
WHERE barcode='D189404954'";

$result = mysqli_query($link, $query);
$row = $result->fetch_array(MYSQLI_NUM);

// See Value for test
//var_dump($row[0]);

if ($row[0] == 1) { 
echo $row[0]; 
} else { 
echo "not in stock";

}

// Close connection
mysqli_close($link);

?>

Upvotes: 1

Views: 67

Answers (1)

Ralph
Ralph

Reputation: 337

Your result code is wrong. == is the comparing operator, whereas = is the assigning operator.

if ($result = 1) {
}

should be:

if ($result == 1) {
}

Upvotes: 1

Related Questions