weixin_33713503 2017-06-20 14:01 采纳率: 0%
浏览 5


i am troubleshooting with update row using AJAX. When i click submit button, the value of poke increases +1 and i need it to update in DB also. Everything needs to work with AJAX. Currently my code works only +1 to poke input with ajax but DB row still not updating. HTML:

                    $result = $mysqli->query("SELECT * FROM users") or die($mysqli->error);
                    while ($users = $result->fetch_assoc()) {
                        <form class="table" name="table" id="table" method="post" enctype="multipart/form-data" autocomplete="off" data-counter="<?php echo $users['id']?>">
                            <div class="Table-row" id="table">
                                <div class="Table-row-item" data-header="Header1"><input class="clear" type="text" name="first_name" id="first_name" value="<?php echo $users['first_name'] ?>"></div>
                                <div class="Table-row-item" data-header="Header2"><input class="clear" type="text" name="last_name" id="last_name" value="<?php echo $users['last_name'] ?>"></div>
                                <div class="Table-row-item" data-header="Header3"><input class="clear" type="text" name="email" id="email_<?php echo $users['email']?>" value="<?php echo $users['email'] ?>"></div>
                                <div class="Table-row-item" data-header="Header4"><input class="clear" type="text" name="poke" id="poke_<?php echo $users['id']?>" value="<?php echo $users['poke']?>"></div>
                                <div class="Table-row-item" data-header="Header5"><input class="poke" type="submit" value="Poke" id="submit" name="submit"></div>
                                <input class="clear" type="hidden" id="hidden" name="hidden" value="<?php echo $users['email']?>">
                                      } ?>


require 'db.php';
if (isset($_POST['submit'])) {
$poke = $mysqli->escape_string($_POST['poke']);
    $email = $mysqli->escape_string($_POST['email']);
    $mysqli->query("UPDATE users SET poke='$poke' WHERE email='$email'") or die($mysqli->error);


$(document).ready(function () {
    $('form').on('submit', function (e) {
        var id = $(this).attr('data-counter');
            type: "post",
            data: $(this).serialize(),
            url: "update.php",
            success: function () {
                var counter = parseInt($("#poke_"+id).val()); // Use form's inner #poke
                alert("form was submited on: " + id);
        return false;
  • 写回答

1条回答 默认 最新

  • MAO-EYE 2017-06-20 14:14

    Not enough info. You need to do more diagnostics.

    E.g: Dump the SQL statement to the output so you can check it is what you expect it to be.

    And run the SQL in, e.g. phpAdmin to check if it updates.

    You may have a problem in the email string, which could be caused by, say, different character encodings between AJAX and the DB. Probably both should use UTF8.




    • ¥80 关于海信电视聚好看安装应用的问题
    • ¥15 vue引入sdk后的回调问题
    • ¥15 求一个智能家居控制的代码
    • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
    • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
    • ¥20 求各位能用我能理解的话回答超级简单的一些问题
    • ¥15 yolov5双目识别输出坐标代码报错
    • ¥15 这个代码有什么语法错误
    • ¥15 给予STM32按键中断与串口通信
    • ¥15 使用QT实现can通信