phpmysqlnullbooleantinyint

How do I update a tinyint value to 1 in php instead of it becoming NULL


I am trying to update a databases boolean's (tinyint) value to 1, but instead, it is updating to NULL and all the other values are changing correctly.

The error I get when I leave it as it is below is:

Bind failed: 0 Execute failed: 2031 No data supplied for parameters in prepared statement

If I change $dealt_Out = 1; to a variable, before the prepared statement, all values are changed correctly except the boolean, which ends up being NULL.

<?php
if(!($stmt = $mysqli->prepare("UPDATE card SET player_Holding = ?, dealt_Out = 1 WHERE id_Card = ?"))){ 
echo "Prepare failed: "  . $stmt->errno . " " . $stmt->error;
}
if(!($stmt->bind_param("iii",$_POST['player_Holding'],$_POST['dealt_Out'],$_POST['id_Card']))){

echo "Bind failed: "  . $stmt->errno . " " . $stmt->error;
}
if(!$stmt->execute()){
echo "Execute failed: "  . $stmt->errno . " " . $stmt->error;
}     else {
echo "Edit " . $stmt->affected_rows . " row to Card Holder. <br/><br/><strong>Returning to 'Make a Move'</strong>";
}

?>

Solution

  • Check well. It should be delt_out = ? not delt_out = 1 If not, take out the $_POST['delt_out'], in the bind_param and remove one i

    I've modified your code. Hope it solves your problem

    <?php
    $dealtout=1;
    if(!($stmt = $mysqli->prepare("UPDATE card SET player_Holding = ?, dealt_Out = ? WHERE id_Card = ?"))){ 
    echo "Prepare failed: "  . $stmt->errno . " " . $stmt->error;
    }
    if(!($stmt->bind_param("iii",$_POST['player_Holding'],$dealtout,$_POST['id_Card']))){
    
    echo "Bind failed: "  . $stmt->errno . " " . $stmt->error;
    }
    if(!$stmt->execute()){
    echo "Execute failed: "  . $stmt->errno . " " . $stmt->error;
    }     else {
    echo "Edit " . $stmt->affected_rows . " row to Card Holder. <br/><br/><strong>Returning to 'Make a Move'</strong>";
    }
    
    ?>