Boo Boo - 3 months ago 10
MySQL Question

PHP Error : need eagle eyes. Mysqli query (T_VARIABLE)

I am receiving the following error:

'$result' (T_VARIABLE) in your code on line 17


This is the code

<?php
error_reporting(E_ALL);
header('Content-Type: application/json');

//https://www.simplifiedcoding.net/retrieve-data-from-mysql-database-in-android-using-volley/
$response = array("error" => FALSE);
require_once 'include/DB_Connect.php';
$db = new Db_Connect();
$conn= $db->connect();

if(isset($_POST['fam_id'], $_POST['points_gained'])){

//CREATE FIELDS
$fam_id = $_POST['fam_id'];
$points_gained = $_POST['points_gained']

$result = mysqli_query($conn, "UPDATE family_member SET points_gained = '$points_gained' WHERE fam_id = $fam_id")or die(mysqli_error($conn));

$row_count = mysqli_affected_rows($conn);

if($row_count>0){
$response["success"] = 1;
$response["message"] = "Updated Sucessfully.";
}
else{
$response["success"] = 0;
$response["message"] = "Failed To Update.";
}
// echoing JSON response
echo json_encode($response);
}
?>


I am unable to understand how to correct it.

Answer

You misssed a semicolon

<?php
    error_reporting(E_ALL);
    header('Content-Type: application/json');

    //https://www.simplifiedcoding.net/retrieve-data-from-mysql-database-in-android-using-volley/
    $response = array("error" => FALSE);
    require_once 'include/DB_Connect.php';
    $db = new Db_Connect();
    $conn= $db->connect();

    if(isset($_POST['fam_id'], $_POST['points_gained'])){

      //CREATE FIELDS
        $fam_id = $_POST['fam_id'];
        $points_gained = $_POST['points_gained'];

        $result = mysqli_query($conn, "UPDATE family_member SET points_gained = '$points_gained' WHERE fam_id = $fam_id")or die(mysqli_error($conn));

        $row_count = mysqli_affected_rows($conn);

        if($row_count>0){
             $response["success"] = 1;
             $response["message"] = "Updated Sucessfully.";
         }
        else{
            $response["success"] = 0;
            $response["message"] = "Failed To Update."; 
         } 
      // echoing JSON response
      echo json_encode($response);
    }
    ?>
Comments