0

I have a table and try to update a value.But now work. I get an error in apache2 log:

Trying to get property of non-object on line 133

Here i s code:

<form id="unblock" method="POST">
<div class="input-field col s11">
    <i class="material-icons prefix">search</i>
    <input id="unlock" type="text" class="validate" name="unlock"> 
    <label for="unlock">Kullanıcı Adı</label>
</div>
<div class="input-field col s11">
<button class=" btn-flat waves-effect waves-light right" type="submit" name="btn_unlock">Remove Block
    <i class="material-icons right">send</i>
</button>
</div>
</form>
<?php 
if(isset($_POST['btn_unlock'])) {
$unlock_username = $_POST['unlock'];
$sql_unlock="UPDATE users SET tries='0' WHERE 
user='$unlock_username'";
if($result_unlock = $mysqli->query($sql_unlock)){
    if($result_unlock->num_rows > 0){     /*LINE 133 IS HERE */
        echo "OK";
        $result_unlock->free();
    } else {
        echo "<script>Materialize.toast('There is no such user', 2000, 'blue lighten-5') </script>";
    }
}
?>
  • It means that `$result_unlock` is not an object. It's *probably* the boolean value `false` because your highly SQL-injectable query is *probably* failing. You'll need to check for errors from the database before assuming the success of a query. You should also use query parameters with prepared statements to avoid the problem in the first place. – David May 18 '17 at 13:29
  • the result can be true as well @see documentation http://php.net/manual/en/mysqli.query.php especially: `Return Values: Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE. ` – Edwin May 18 '17 at 13:32
  • I have conenction at the top of page. I dont need to write it.Because I have working code about same table in same page `$mysqli = new mysqli($dbServerName, $dbUsername, $dbPassword, $dbName); // check connection if($mysqli === false){ die("ERROR: Could not connect. " . $mysqli->connect_error); }` Additionally, I have another working query and it has `if($result_devicename->num_rows > 0){ ...
    `
    – Tevfik Ceydeliler May 18 '17 at 14:11
  • I read some manual. thyen I think I have to use mysql_affected_rows instead of num_rows – Tevfik Ceydeliler May 18 '17 at 14:31

0 Answers0