Home>

I want to get MySQL fields in PHP and handle them as variables.

Error message

MySQL fields cannot be handled with PHP and handled as variables

Error message
Notice: Object of class mysqli_result could not be converted to int in
Applicable source code

$mysqli = mysqli_connect ("localhost","name","path","data");
if ($_SERVER ["REQUEST_METHOD"] ==="POST") {
$water = 0;
$sql ="SELECT water FROM data LIMIT 0,1" ;;
$a = 1 + mysqli_query ($mysqli, $sql);
$water = $a + 1;
$sql ="UPDATE data SET water = $water" ;;
$res = mysqli_query ($mysqli, $sql);

php
  • Answer # 1

    A hint.

    $sql = "SELECT water FROM data LIMIT 0,1";
    $a = 1 + mysqli_query ($mysqli, $sql);
    $water = $a + 1;


    $sql = "SELECT water FROM data LIMIT 0,1";
    $res = mysqli_query ($mysqli, $sql);
    var_dump ($res);

    Check the value returned by mysqli_query like this.


    <? php
    $sql = "SELECT water FROM data LIMIT 0,1";
    $result = mysqli_query ($mysqli, $sql);
    $rows = $result->fetch_assoc ();
    $rows ['water'];
    $water = $rows ['water'] + 1;