0

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 Answers2

1

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));

Passionate Coder
  • 7,154
  • 2
  • 19
  • 44
  • I started using error reporting, found a few errors, fixed them, but THE PROBLEM IS STILL THERE. no errors show up, but when i add , blackTowellCount='".$blackTowellCount."' to the SQL, it still does not work. There are no errors before or after adding this, but it works before. – Matt Molsberry Jul 10 '16 at 21:51
  • Ok once echo your query with this blackTowellCount and see what query it is and after getting query run it in phpmyadmin and see what error does phpmyadmin gives – Passionate Coder Jul 11 '16 at 01:28
0

There was a space in front of "blackTowellCount" in the database. I hate programming.