php - MySQL 插入在 jQuery Mobile 中不起作用

标签 php jquery mysql insert

我正在尝试使用插入查询创建注册表单,该查询已在我之前制作的预订表单中使用,但它似乎没有插入,并且在控制台日志中给出了此错误消息

Uncaught Error: cannot call methods on page prior to initialization; attempted to call method 'bindRemove' coming from an external JS file.

非常感谢任何帮助。

这是来自 PHP 包含

<?php

//This adds the connection file which has the details to connect to the database and what database to connect to
include_once('connection.php');

//Checks if the submit button is not set
if(!isset($_POST['submit']))
{
exit;
}
    //Declared Variables
    $first = $_POST['fname'];
    $surname = $_POST['sname'];
    $password= $_POST['password'];
    $email= $_POST['email'];
    $postcode= $_POST['postcode'];
    $GPID= $_POST['Practice'];


    //Database Connection, this connects to the database using the connection.php
    $conn=ConnectionFactory::connect();

    //Insert Query
    $query="INSERT INTO `User`(`UserID`, `First_name`, `Surname`, `Username`, `Password`, `email`, `Image`, `Postcode`, `StoreID`, `DeptNo`, `AccessID`, `GPID`) VALUES (NULL, :fname, :sname, NULL, :password, :email, NULL, :postcode, 1, 1, 1, :GPID)";

    $stmt=$conn->prepare($query);

    //Binding values
    //$stmt->bindValue(':post', $Post);
    $stmt->bindValue(':fname', $first);
    $stmt->bindValue(':sname', $surname);

    $stmt->bindValue(':password', $password);
    $stmt->bindValue(':email', $email);
    $stmt->bindValue(':postcode', $postcode);
    $stmt->bindValue(':GPID', $GPID);

    $affected_rows = $stmt->execute();

    //Message if insert is Successful
    if($affected_rows==1){
        print "<script type=\"text/javascript\">"; 
        print "alert('Register Successful')"; 
        print "</script>";
        exit;
        }else{
        print "<script type=\"text/javascript\">"; 
        print "alert('Unable to register at this moment')"; 
        print "</script>";
        exit;   
        }




    //Terminates the connection
            $conn=NULL;
?>

这是表格

 <section data-role="content">
    <h1>Register to be able to Book Appointments on the go</h1>
    <form id ="register" accept-charset="UTF-8" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"])?>" method="POST">

        <fieldset data-role="fieldcontain">
        <label for="fname">First name:</label>
        <input type="text" name="fname" id="fname" required>
        </fieldset>    

        <fieldset data-role="fieldcontain">
        <label for="sname">Surname:</label>
        <input type="text" name="sname" id="sname" required>
        </fieldset>

        <fieldset data-role="fieldcontain">
        <label for="password">Password:</label>
        <input type="Password" name="password" id="password" required>
        </fieldset>

        <fieldset data-role="fieldcontain">
        <label for="Cpassword">Confirm Password:</label>
        <input type="Password" name="Cpassword" id="Cpassword" required>
        </fieldset>

        <fieldset data-role="fieldcontain">
        <label for="email">Email:</label>
        <input type="email" name="email" id="email" required>
        </fieldset>

        <fieldset data-role="fieldcontain">
        <label for="postcode">Postcode:</label>
        <input type="text" name="postcode" id="postcode" required>
        </fieldset>

        <fieldset data-role="fieldcontain">
        <select id="Practice" name="Practice" class="required">
            <option value="null">Select a Practice</option>
            <option value="1">Guide Bridge Medical Centre</option>
            <option value="2">The University Health Centre</option>
            <option value="3">King Street Medical Centre</option>
            <option value="4">Mossley Medical Centre</option>
        </select>
        </fieldset>

        <input type="submit" id="submit" name="submit" data-icon="check" data-iconpos="top" value="Register"/>
        <?php include 'registerInsert.php';?>
     </form>

最佳答案

代替线条

 $affected_rows = $stmt->execute();

替换为

 mysqli_query($conn, "INSERT INTO `User`(`UserID`, `First_name`, `Surname`, `Username`, `Password`, `email`, `Image`, `Postcode`, `StoreID`, `DeptNo`, `AccessID`, `GPID`) VALUES (NULL, :fname, :sname, NULL, :password, :email, NULL, :postcode, 1, 1, 1, :GPID)");

关于php - MySQL 插入在 jQuery Mobile 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29850163/

相关文章:

php - 在迁移 laravel 5.1 中设置自动增量字段从 1000 开始

php - 如何使用 PEAR 和 PHP 创建表?

javascript - 在 jQuery 实时预览 div 中将文本转换为图像

jquery - 在 html 表格中卡住标题

mysql - 列出用户根据纬度和经度动态指定的半径内的用户

php - 拉拉维尔 4 : Many to Many with extra relationship

php - URL 从一台服务器重定向到另一台服务器

javascript - 从外部函数访问 $http 数据

java - 如何使用 JOOQ 批量执行

mysql - 如何在 mysql 中的现有行之间插入新行?