gpt4 book ai didi

javascript - Jquery表单提交空值到Mysql

转载 作者:行者123 更新时间:2023-11-29 20:37:19 25 4
gpt4 key购买 nike

我的 IntelXDK HTML5 移动应用程序表单向 MySQL 数据库提交空值。

我的 HTML(单文件应用程序)

<label class="item item-input widget uib_w_6 d-margins" data-uib="ionic/input" data-ver="0" id="fullname">
<input type="text" placeholder="Fullname" name="fullname">
</label>
<label class="item item-input widget uib_w_7 d-margins" data-uib="ionic/input" data-ver="0" id="email">
<input type="email" placeholder="Email" name="email">
</label>
<label class="item item-input widget uib_w_8 d-margins" data-uib="ionic/input" data-ver="0" id="pass">
<input type="password" placeholder="Password" name="pass">
</label>
<button class="button widget uib_w_9 d-margins button-positive" data-uib="ionic/button" data-ver="0" id="signup">
Create Account
</button>
<span class="uib_shim"></span>

我的JS

$(document).on("click", "#signup", function (evt) {
/* your code goes here */
//these two lines take the values from inputs using jquery
var input1 = $("#fullname").val();
var input2 = $("#email").val();
var input3 = $("#pass").val();

//jquery ajax to send values to php using POST
$.ajax({
type: 'POST',
url: 'http://localhost/signup.php',
data: {
fullname: input1,
email: input2,
pass: input3
},
success: function (response) {
//from php using echo
alert(response);
}
});

return false;
});

以及 PHP 文件

<?php
// Create connection
$conn = new mysqli("localhost", "user", "pass", "dbname");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$fullname = Trim(stripslashes($_POST['fullname']));
$email = Trim(stripslashes($_POST['email']));
$pass = Trim(stripslashes($_POST['pass']));

$sql = "INSERT INTO login (fullname, email, pass) VALUES ('$fullname','$email', '$pass')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

提交此表单后,它会在 MySQL 中创建空记录。

感谢任何帮助。

最佳答案

发生这种情况是因为

<input type="text" placeholder="Fullname" name="fullname">

没有像 id="fullname"这样的可用 ID,而您正在引用它。

关于javascript - Jquery表单提交空值到Mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38742096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com