MySQL更新查询更新一列但不更新其他列

时间:2016-12-06 15:10:48

标签: php mysql ajax

我有一个MySQL查询成功更新了所需的两列中的一列而不是另一列。成功的列,productionstage是数据类型:varchar和不成功的列floornotes是数据类型:text。我测试了使用floornotes数据类型:varchar没有成功。 floornotes和productionstage的数据来自一个html表单,其数据通过ajax发送到php。 productionstage是菜单选择,floornotes是textarea。关于这个问题的任何想法?我没有从服务器收到任何错误,当我在我的ajax中为传递的floornotes值执行console.log()时,我每次都看到正确的字符串。

我的代码:

HTML:

<form id="workorderMovement" name='workorderMovement_form' action="workordermovementGET.php" method="post">



<fieldset id="userid">

  <span>Welcome <?php echo $user ?> </span>

</fieldset> 




<fieldset id="sgnum">

<fieldset id="fieldset" style="text-align: center;"> 
  <span>Please enter the SG Number</span>
</fieldset>

<input type="text" name="sgnumber" id="sgnumber"> &nbsp;&nbsp;&nbsp; <input type="button" name="searchButton" id="searchButton" value="SEARCH">

</fieldset> 


<br/>
<br/>



<fieldset id="stageSelectField">

  <fieldset id="fieldset" style="text-align: center;"> 
    <span>Please select the Stage Completed</span>
  </fieldset>

<select name="stageSelect" id="stageSelect">
  <option value="Please Select">Please Select</option>
  <option value="Film Done">Film Done</option>
  <option value="Staged Done">Staged Done</option>
  <option value="Cleanroom Done">Cleanroom Done</option>
  <option value="GB2 Done">GB2 Done</option>
  <option value="Bagging Done">Bagging Done</option>
  <option value="Inspection Done">Inspection Done</option>
  <option value="LC Inspection Done">LC Inspection Done</option>
  <option value="IGU Done">IGU Done</option>
</select>

</fieldset> 


<br/>
<br/>


<fieldset id="floorNotesField">

  <fieldset id="fieldset" style="text-align: center;"> 
    <span>Please enter any new work order notes</span>
  </fieldset>

  <textarea type="text" name="floorNotes" id="floorNotes" class="floorNotesText"></textarea>

</fieldset>


<br/>
<br/>
<br/>

</form> <!-- End Work Order Movement Form -->

<fieldset id="doneButtonField">

  <input type="button" name="doneButton" id="doneButton" value="DONE">

</fieldset> 

MY AJAX:

         j("#doneButton").click(function(){


            //send Workorder Movement Data values to php using ajax.

                var sgnumber = j('#sgnumber').val();
                var stageselect = j('#stageSelect').val();
                var floornotes = j('#floorNotes').val();

             console.log(floornotes);

                j.ajax ({
                    method: 'POST',
                    url: "workordermovementUPDATE.php",
                    data: {sgNumber: sgnumber, stageSelect: stageselect, floorNotes: floornotes},
                    dataType: 'json',
                    success: function(){}
                 });

        });

我的PHP:

    <?php 


include('inc.php');


//Get Table Options.
if (isset($_POST['sgNumber'])) {
    $sgNumber = $_POST['sgNumber'];

    if (isset($_POST['stageSelect'])) {
        $stageSelect=$_POST['stageSelect'];
    }
    if (isset($_POST['floorNotes'])) {
        $floorNotes=$_POST['floorNotes'];
    }

    //connect  to the database 
    $conn = new mysqli($servername, $username, $password, $dbname);

    // Check connection
    if(mysqli_connect_errno() ) {
        printf('Could not connect: ' . mysqli_connect_error());
        exit();
    }

    $conn->select_db($dbname);

    if(! $conn->select_db($dbname) ) {
        echo 'Could not select database. '.'<BR>';
    }

    $sql= "UPDATE invoicesDec2016 SET productionstage = ?, floornotes = ? WHERE id = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param('ssi', $stageSelect, $floornotes, $sgNumber);
    $stmt->execute();       

    if(mysqli_query($conn, $stmt)){
        echo "".$sgnumber." Updated Successfully!";
    } else {
        echo "ERROR: Could not update ".$sgnumber."".mysqli_error($conn)."";
    }


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//Free the result variable. 
 $result->free();


//Close the Database connection.
 $conn->close();

}//End If statement

?>

注意:当我进行更新时,PRODUCstage会成功更新,之前的floornotes内容会被删除。

0 个答案:

没有答案