dqwr32867 2015-12-02 23:36
浏览 62

使用JSON和PHP更新数据库

I really appriciate your help, i am loseing my mind here I don't get any errors, everything seems ok, but the db is not updating?!!!

in firefox consol i get no error and on the server log no error ?!!

i get the alert saying insert successful!! but as i said, my db dosent update?!

here is my code

<div id="landmark-1" data-landmark-id="1">
<form  id="insertContact" >


    <input name="a1" id="a1" type="text" placeholder="" onFocus="$(this).val('')" value="">
    <label> name </label>
  
 
    <input name="a2" id="a2" type="text" placeholder="" onFocus="$(this).val('')" value="">
    <label>message</label>


<input type="submit" 
  id="submit" name="submit" value="Submit" />
 </form>
</div>

and this is my js file

  $(document).ready(function(){
    $("#submit").click(insertContact);
  });
  function insertContact(){
    console.log("Entering insertContact()");
     $("#insertContact :input").serializeArray(),
    $.post("update.php",
  
    function(json){
      if(json== null || json == 'undefined')
        alert("Insert failed");
      else
        alert("Insert successful");
        
    });
    return false;
  }

and this is my php file

<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');

$server = "localhost";
$username = "xxxxxxx";
$password = "xxxxxxx";
$database = "xxxxxxx";

$con = mysql_connect($server, $username , $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);
$iid=1;
$ab1 = mysql_real_escape_string($_POST["a1"]);
$ab2 = mysql_real_escape_string($_POST["a2"]);



$sql = "UPDATE my_table SET
    field_1='$ab1',
    field_2='$ab2'

    
    WHERE id=$iid";

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 数学建模,尽量用matlab回答,论文格式
    • ¥15 昨天挂载了一下u盘,然后拔了
    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
    • ¥20 易康econgnition精度验证
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能