我有一个 ajax 调用,它将数据从表单发送到 php 文件,然后将该数据插入数据库。我die
在所说的 php 文件中调用了,因为我想尝试一些东西,但它不起作用。
addUserForm.php
<script>
$(document).ready(function () {
var $form = $('form');
$form.submit(function (event) {
event.preventDefault();
var formData = $form.serialize(),
url = $form.attr('action');
$.ajax({
type: "POST",
url: url,
data: formData,
success: function () {
//$("#div1").load("table.php");
alert('User Successfully Added');
document.getElementById("form1").reset();
}
});
});
});
</script>
这是php文件:
添加用户.php
<?php
include('sqlconnection.php');
die('here');
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$middlename = $_POST['mname'];
$password = $_POST['pword'];
$username = $_POST['uname'];
$gender = $_POST['gender'];
$utype = $_POST['utype'];
$query = "INSERT INTO user (firstname,lastname,middlename,gender) VALUES ('$firstname','$lastname','$middlename','$gender')";
mysqli_query($con,$query);
$result = mysqli_query($con,"SELECT id FROM user WHERE firstname = '$firstname'");
$row = mysqli_fetch_assoc($result);
$uid=$row['id'];
$result = mysqli_query($con,"INSERT INTO accounts (u_id,username,password,account_type) VALUES ('$uid','$username',md5('$password'),'$utype');");
?>
即使有die
呼叫,adduser.php
它仍然会提醒用户已成功添加。