Reputation: 27
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();
}
}
?>
Upvotes: 0
Views: 287
Reputation: 155
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.
Upvotes: 0
Reputation: 2277
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();
}
Upvotes: 0