drn34916 2016-01-12 13:11
浏览 135

如何使用AJAX按钮单击更新数据库中的单元格?

This code doesn't work! The console.log prints

"You are not subscribed to newsleter"

I want to be able to click the button and then it says

"You are subscribed to newsleter"

This is my HTML

<button onclick="subscribe()">Subscribe to newsletter</button>

This is my script

function subscribe(){
    $.ajax({
        url: 'php/test.php',
        success: function(data){
            console.log(data);
        }
    });
    return false;
}

This is my PHP

<?php
$myQUERY ="SELECT * FROM user";
$myQUERY .=" UPDATE user";
$myQUERY .=" SET Subscribed='1'";
$myQUERY .=" WHERE DisplayName='Henry'";

$row = mysqli_fetch_array($result);
if ($row['Subscribed'] == 1) {
    echo 'You are subscribed to newsleter';
}
else
{
    echo 'You are not subscribed to newsleter';
}
?>

In the Database, newsletter subscription is set to 1 when subscribed and 0 when not subscribed

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!