dongren4758 2013-11-26 23:38 采纳率: 0%
浏览 97
已采纳

PHP mysql_query update总是返回true

$result always return true, even though there is no parameter passed to the SQL query.

Everything else is all right and I have tested it in the database.

<?php
     require('dbConnection.php');
    $lon   = $_POST['lon'];
    $lat   = $_POST['lat'];
    $time  = $_POST['time'];
    $date = $_POST['date'];
    $eTime = $_POST['eTime'];
    $eDate = $date;
    $orderID = $_POST['orderID'];


    if($db_found){

        $query = "UPDATE `PostmanLocation` 
        SET `longitude`= '$lon',`latitude`= '$lat',`time`= '$time', `date`='$date'
        WHERE `postID`= '$name'";

        $result=0;

        $result = mysql_query($query) or die("MySQL error:".mysql_error());
        echo $result;
        if($result==1){

                $query = "
                UPDATE `Order` 
                SET `eTime`= '$eTime',`eDate`= '$eDate' 
                WHERE `orderID` = 'orderID'";

                 $result=0;
                $result = mysql_query($query);
                echo $result;
                if($result == 1){
                    $response["success"] = 1;

                } else{  
                    $response["success"] =0;   
                }

        }else{
            $response["success"] = 0;
        }
        echo json_encode($response);
     }
    ?>
  • 写回答

1条回答 默认 最新

  • douchuang4402 2013-11-26 23:47
    关注
    $result = mysql_query($query) or die("MySQL error:".mysql_error());
    

    In the instruction above, $result will never be false : either mysql_query returns true, or the script dies.

    If you rather want to check if your UPDATE query had any effect at all, you can use this:

    Use mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.

    http://us3.php.net/manual/en/function.mysql-affected-rows.php

    Also note that mysql_ functions are deprecated. You should switch to PDO or mysqli.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面