0

Hi guys my php update query doesnt return me any value. It should return me success or failed but its not can you guys fix this?

disregard securities here I just use this query for my android app.

Here is my code.

<?php
include_once("connection.php");

if(isset($_POST['txtCar_No']) &&  isset($_POST['txtCarModel']) && 
    isset($_POST['txtCarType']) && isset($_POST['txtCapacity']) && 
    isset($_POST['image']) && isset($_POST['txtFuelType']) && 
    isset($_POST['txtPlateNumber']) &&  isset($_POST['txtcarPrice']))
{
    $now = DateTime::createFromFormat('U.u', microtime(true));
    $id = $now->format('YmdHis');

    $upload_folder = "upload";
    $path = "$upload_folder/$id.jpeg";
    $fullpath = "http://carkila.esy.es/$path";

    $image = $_POST['image'];
    $Car_No = $_POST['txtCar_No'];
    $Car_Model = $_POST['txtCarModel'];
    $Car_Type = $_POST['txtCarType'];
    $Capacity = $_POST['txtCapacity'];
    $Fuel_Type = $_POST['txtFuelType'];
    $PlateNumber = $_POST['txtPlateNumber'];
    $carPrice = $_POST['carPrice'];

    $query = "UPDATE tbl_cars SET Car_Model='$Car_Model', Car_Type='$Car_Type', Capacity='$Capacity', fuelType='$Fuel_Type' ,carPlatenuNumber='$PlateNumber', image='$fullpath' , carPrice = '$carPrice' WHERE Car_No=$Car_No";

    $result = mysqli_query($conn,$query);

    echo $Car_No;

    if($result > 0){
        echo "success";   
        exit();
    } else {
        echo "failed";
        exit();
    }
}
?>
3
  • Please check this Question. Since its related and handled before Commented Sep 15, 2016 at 7:57
  • you can use mysqli_error function and check error in your query. it shows any error in query Commented Sep 15, 2016 at 7:59
  • use mysqli_num_rows($result) Commented Sep 15, 2016 at 8:01

2 Answers 2

0

You have to use mysqli_affected_rows($conn) to get rows affected by this update query.

E.g.:

$result = mysqli_query($conn,$query);
$count = mysqli_affected_rows($conn);



if($result == TRUE && $count > 0){
    echo "success";   
    exit();
} else {   
    print_r (mysqli_error($conn));
    echo "failed";
    exit();
}
Sign up to request clarification or add additional context in comments.

Comments

0

What is the value in $return after $result = mysqli_query($conn,$query);?

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. Returns FALSE on failure.

So the value of $result after your UPDATE-query can only be true or false, nothing else.

Your echo..if... can be simplified to one line:

echo ($result?"success":"failed");

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.