简体   繁体   English

PHP Mysql更新查询不返回任何内容

[英]PHP Mysql update query returns nothing

Hi guys my php update query doesnt return me any value. 嗨,大家好,我的php更新查询没有返回任何值。 It should return me success or failed but its not can you guys fix this? 它应该使我success还是failed但是你们不能解决这个问题吗?

disregard securities here I just use this query for my android app. 在这里不考虑证券,我只对我的Android应用程序使用此查询。

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();
    }
}
?>

You have to use mysqli_affected_rows($conn) to get rows affected by this update query. 您必须使用mysqli_affected_rows($conn)来获取受此更新查询影响的行。

Eg: 例如:

$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();
}

What is the value in $return after $result = mysqli_query($conn,$query); $result = mysqli_query($conn,$query);之后, $return的值是多少? ?

For successful SELECT , SHOW , DESCRIBE or EXPLAIN queries, mysqli_query() will return a mysqli_result object . 对于成功的SELECTSHOWDESCRIBEEXPLAIN查询, mysqli_query()将返回mysqli_result object For other successful queries mysqli_query() will return TRUE . 对于其他成功的查询, mysqli_query()将返回TRUE Returns FALSE on failure. 失败时返回FALSE

So the value of $result after your UPDATE -query can only be true or false, nothing else. 因此, UPDATE查询后的$result值只能为true或false,不能有其他值。

Your echo..if... can be simplified to one line: 您的echo..if...可以简化为一行:

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

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM