dongyou9721 2018-11-24 07:15
浏览 197
已采纳

too long

I am trying to make a QR code scanner using Vue.js and instascan. I have already done the scanning part. Now I am stuck in this process where I have to retrieve the data from MySQL using an Ajax request. I can't seem to retrieve the data from the input form.

Here is my HTML code:

    <form id="cont_disp" method="post">
    <label class="disptext" style="margin-left: 41%;">Load user credits</label>

    <div class="form-group" id="app">
        <input v-for="scan in scans" :key="scan.date" hidden :title="scan.content" class="form-control" id="qr_user" name="qr_user" placeholder="Scan User QR Code":value="scan.content" style="width: 15%; font-size: 20px; left: 44%; position: absolute; top: 30%; border: 0; background: transparent;">
    </div>
    <div class="video-container">
        <video id="preview"></video>
    </div>


    <div class="content-display">

            <label class="disptext" style="font-size: 20px;">Username: </label>
            <input type="button" name="" class="login" value="Search" style="margin-left: 70%; font-size: 20px;" id="qr_search">
            <br /><br />
            <label class="disptext" style="font-size: 20px;">Current Balance: </label><input type="text" class="disptext" id="userbal" style="font-size: 20px; left: 44%;"><br /><br />
            <label class="disptext" style="font-size: 20px;">Enter credit amount: </label><input type="number" name="loadcred" id="loadcred" style="margin-left: 28%;" required placeholder="Credit amount"><br /><br />
            <input type="submit" name="credsub" id="credsub" value="Load Credits" class="login" style="width: 50%; margin-top: 3%;">

    </div>
</form>

And here is the php query.

   include 'dbcon.php';
   $qr_user = $_POST['qr_user'];
   $query = mysqli_query($con, "SELECT username, credits FROM useracc WHERE username='$qr_user'");
   $row = mysqli_fetch_array($query);
   echo json_encode($row);

And the Ajax request:

  $("#qr_search").click(function(){
    var qr_user = $("#qr_user").val();
    $.ajax({
        type: "post",
        url: "../Capstone/qrdata.php",
        data: formData = {username:qr_user},
        success: function(data){
            // can't seem to do anything here since I can't fetch any data from php
        }
    });
});
  • 写回答

1条回答 默认 最新

  • donglu2008 2018-11-24 07:25
    关注

    Change this:

    $qr_user = $_POST['qr_user'];

    to:

    $qr_user = $_POST['username'];
    

    to solve the issue because the name is mismatched.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办