weixin_33736649 2016-08-17 03:59 采纳率: 0%
浏览 83

更新数据记录onBlur

I am trying to update a record in a database onBlur but it does not work. Any ideas on how I can achieve this? my code looks like below.

JS

$(function () {
$("textarea").blur(function() {

       var meta_value =   $(this).val();
                var meta_key   =   $(this).attr("id");

             alert(meta_value + meta_key);


    $.get('script-url', { key: meta_Key, value: meta_value}, function(data) {

    });
});
});

PHP

<?php


if(isset($_POST['key']))
{
   $meta_value = $_REQUEST['value'];
   $meta_key = $_REQUEST['key'];


$servername = "hhh";
$username = "hhh";
$password = "hhh";
$dbname = "hhh";


 global $wpdb;
 $user_ID = get_current_user_id();  



// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 



$sql = "UPDATE wp_usermeta SET meta_value = $meta_value WHERE meta_key = $meta_key AND user_id= $user_ID";

if ($conn->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $conn->error;
}


}
?>
  • 写回答

2条回答 默认 最新

  • DragonWar% 2016-08-17 05:08
    关注

    Try this ;)

    You are sending key & value to server not meta_key;

    So update this condition

    if(isset($_POST['meta_key'])){
    

    to

    if(isset($_POST['key'])){
    
    评论

报告相同问题?

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表