dtuct88226 2016-07-10 03:04
浏览 44

一个字段使SQL UPDATE语句无法工作

This has consumed my Saturday. Please help.

I have a large form that I need to update a record in a MySQL database table hosted on a GoDaddy shared account. There are 18 records I'm trying to update when the form is submitted, but so far I've only gotten 17 to do so. The 2nd to last field, "blackTowellCount", causes problems when I include it in the UPDATE statement.

If I exclude the field in question from the SQL statement, ALL 18 fields successfully POST the data to the PHP file and the 17 listed in the SQL statement upload just fine. When I include the blackTowellCount field, the UPDATE stops working and the form no longer POSTS the data to the PHP form. WTF?!

You'll also notice that there's a nearly identical field, "whiteTowellCount" that updates just fine.

portion of the form:

<div class="well">
               <div class="row">
                 <div class="col-md-1">
                 </div>
                 <div class="col-md-2"> 
                   <label for="blackTowellCount" class="pull-right">Black Towells</label>
                 </div>
                 <div class="col-md-3">
                      <input type="text" class="form-control" id="blackTowellCount" name="blackTowellCount" placeholder="black towell #"/>
                 </div>
                 <div class="col-md-2">
                         <label for="whiteTowellCount" class="pull-right">White Towells</label>
                 </div>
                 <div class="col-md-3">                
                   <input type="text" class="form-control" id="whiteTowellCount" name="whiteTowellCount" placeholder="white towell #"/>
                 </div>
                 <div class="col-md-1">
                 </div>


               </div>       
             </div>

Functional SQL:

$addIntakeSQL = mysqli_query($link,"UPDATE Act SET w9FilePath='".$w9Upload_destination."', riderFilePath='".$riderUpload_destination."', hospRiderFilePath='".$hospRiderUpload_destination."', inputFilePath='".$inputListUpload_destination."', stageFilePath='".$stagePlotUpload_destination."', backlineFilePath='".$backlineUpload_destination."', bathTowellCount='".$bathTowellCount."', breakfastCount='".$breakfastCount."', lunchCount='".$lunchCount."', dinnerCount='".$dinnerCount."', breakfastRestriction='".$breakfastRestriction."', lunchRestriction='".$lunchRestriction."', dinnerRestriction='".$dinnerRestriction."', arrivalDate='".$arrivalDate."', arrivalTime='".$arrivalTime."', needTransport='".$needTransport."', whiteTowellCount='".$whiteTowellCount."' WHERE actID='".$actID."'") or die (mysqli_error());

Broken SQL:

$addIntakeSQL = mysqli_query($link,"UPDATE Act SET w9FilePath='".$w9Upload_destination."', riderFilePath='".$riderUpload_destination."', hospRiderFilePath='".$hospRiderUpload_destination."', inputFilePath='".$inputListUpload_destination."', stageFilePath='".$stagePlotUpload_destination."', backlineFilePath='".$backlineUpload_destination."', bathTowellCount='".$bathTowellCount."', breakfastCount='".$breakfastCount."', lunchCount='".$lunchCount."', dinnerCount='".$dinnerCount."', breakfastRestriction='".$breakfastRestriction."', lunchRestriction='".$lunchRestriction."', dinnerRestriction='".$dinnerRestriction."', arrivalDate='".$arrivalDate."', arrivalTime='".$arrivalTime."', needTransport='".$needTransport."', blackTowellCount='".$blackTowellCount."', whiteTowellCount='".$whiteTowellCount."' WHERE actID='".$actID."'") or die (mysqli_error());

portion of .PHP file:

    $bathTowellCount = $_POST['bathTowellCount'];
    $breakfastCount = $_POST['breakfastCount'];
    $lunchCount = $_POST['lunchCount'];
    $dinnerCount = $_POST['dinnerCount'];
    $breakfastRestriction = $_POST['breakfastRestriction'];
    $lunchRestriction = $_POST['lunchRestriction'];
    $dinnerRestriction = $_POST['dinnerRestriction'];

    $arrivalDate = $_POST['arrivalDate'];
    $arrivalTime = $_POST['arrivalTime'];
    $needTransport = $_POST['needTransport'];

    $blackTowellCount = $_POST['blackTowellCount'];
    $whiteTowellCount = $_POST['whiteTowellCount'];

    $addIntakeSQL = mysqli_query($link,"UPDATE Act SET w9FilePath='".$w9Upload_destination."', riderFilePath='".$riderUpload_destination."', hospRiderFilePath='".$hospRiderUpload_destination."', inputFilePath='".$inputListUpload_destination."', stageFilePath='".$stagePlotUpload_destination."', backlineFilePath='".$backlineUpload_destination."', bathTowellCount='".$bathTowellCount."', breakfastCount='".$breakfastCount."', lunchCount='".$lunchCount."', dinnerCount='".$dinnerCount."', breakfastRestriction='".$breakfastRestriction."', lunchRestriction='".$lunchRestriction."', dinnerRestriction='".$dinnerRestriction."', arrivalDate='".$arrivalDate."', arrivalTime='".$arrivalTime."', needTransport='".$needTransport."', whiteTowellCount='".$whiteTowellCount."' WHERE actID='".$actID."'") or die (mysqli_error());

}       
  • 写回答

2条回答 默认 最新

  • dongxiansi0158 2016-07-10 04:12
    关注

    Hi First of all as all suggested your code is open to SQL injections, Use PDO instead . Second php has its functions to display errors include them if you got nothig to do.

    add these lines at top of your page

    error_reporting(E_ALL);
    ini_set('display_errors',1);
    

    also you have not given mysqli_error() its parameter

    Replace die(mysqli_error()); with die(mysqli_error($link));

    评论

报告相同问题?

悬赏问题

  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测