簡體   English   中英

PHP中的更新查詢問題

[英]Update Query issue in PHP

$id=mysql_real_escape_string($levelid);
        $l=mysql_real_escape_string($level);
        $levDes=mysql_real_escape_string($leveldescription );
        $sql="UPDATE `levels` SET level='$l',leveldescription='$levDes' WHERE id='$id' LIMIT 1";
        $result=mysql_query($sql);
        if(!$result){throw new Exception(mysql_error());}
        $effectedRows=mysql_affected_rows();
        if(!$effectedRows){
            $sql="SELECT * FROM `levels` WHERE level='$l' AND id='$id' LIMIT 1";
            $result=mysql_query($sql);
            if(!$result){throw new Exception(mysql_error());}
            if(mysql_num_rows($result)==0){
                throw new Exception("Could not find Level's record in database to update.");
            }else{//no changes to the row 
                return "Level successfully updated in database although no changes were detected.";
            }//else
        }//if
        return "Level successfully updated in database.";
  1. 當我嘗試更新時,級別會更新,但不會更新級別說明。
  2. 級別也是唯一的,但是當我輸入重復值時它不會引發錯誤。盡管數據庫沒有受到影響。

您的代碼似乎很好,在查詢之前您是否檢查過$ levDes是否具有某些值。 回顯查詢或$ levDes。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM