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