ajax PHP给Db带来了不一致的结果

时间:2014-10-16 16:07:16

标签: php jquery ajax

请参阅以下代码:

当我去编辑数据时,返回的保存数据是一个字段的状态'可以正确保存,或者有些字母在保存时会被删除。 在状态字段中,有三个可能的值' credit',' debit'或签证' '借记'和签证'值会被返回并正确保存,但保存的一些信用值就像' cr'即使文本框显示' credit'在保存之前...甚至清除字段并输入“信用卡”#39;在保存之前没有帮助..

CurrentPage.EditItem = function(id) {
if (confirm('Are you sure?')) {
    console.log("DetailPage :: edit");
    var name = $("#name").val();
    var itemm = $("#itemm").val();
    var amount = $("#amount").val();
    var status = $("#status").val();
    var Uid = localStorage.getItem("Uid");
    //formData = {
     //   UId: sessionStorage.userId,
       // itemm: $("#name").val(),
       // amount: $("#amount").val(),
       // status: $("#status").val(),
      // }
     if (itemm == "") {
        alert("Please enter item");
    } else if (amount == "") {
        alert("Please enter office amount");
    } else if (status == "") {
        alert("Alert", "Please enter phone status");
    } else {
        $.ajax({
            type:'POST',
            url:'http://www.mywebsite.com/edit.php',
            data:{'Uid':Uid,'itemm':itemm,'amount':amount,'status':status},
             crossDomain: true, // enable this
            success: function(data) {
                alert("Edit item success");
                window.location.href = "listof.html"    
            },
            error: function() {
                alert("Edit user gone wrong");
            }

            });
            }
}
};

HTML

<div class="car">
    <ul class="view">
        <li >Item:</li>

        <li ><input id="itemm" name="itemm" type="text"></li>

        <li >Amount:</li>

        <li ><input id="amount" name="amount" type="text"></li>

        <li >Status:</li>

        <li ><input id="status" name="status" type="text"></li>


    </ul>
   </div>
   <div class="car" style="margin-bottom:40px;">
        <button id="edit" class="btn btn-positive btn-block" onclick="currentPage.EditItem();">EDIT ITEM</button>
   </div>
   <div class="car" style="margin-bottom:40px;">
        <button class="btn btn-negative btn-block" onclick="currentPage.deleteItem();">REMOVE ITEM</button>

PHP

<?php

header('Content-type: application/json');
$con=mysqli_connect("localhost","mxxxxxx","xxxxx89x78x","ccxcxcxcxc_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$itemm_id = $_POST['Uid'];
$itemm_itemm = $_POST['itemm'];
$itemm_amount = $_POST['amount'];
$itemm_status = $_POST['status'];

$qry = "UPDATE balance1 SET itemm = '$itemm_itemm', amount = '$itemm_amount' , status = '$itemm_status' 
WHERE id ='$itemm_id'";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "1 record updated";

mysqli_close($con);

 ?>

有什么想法???

0 个答案:

没有答案