通过 HTML 表单添加新的 WordPress 用户
我想通过 HTML 表单向 wp_users 表添加一个新的 WordPress 用户,但由于某种原因,它不起作用。可能出什么问题了?我需要插入其他输入吗?或者也许为此创建一个不同的表?
这是我的 HTML 代码:
<span class="bottomForm">
<p style="color:red; font-weight: bold;">
< חזרה לעגלת הקניות </p> <button class="bottomButton" type="button" onclick="submitForm()"
name="save_contact">המשך
לאפשרויות משלוח</button>
</span>
</form>
<script type="text/javascript">
function submitForm() {
var email = $('input[name=user_email]').val();
var password = $('input[name=user_pass]').val();
var formData = {
email: user_email,
password: user_pass
};
$.ajax({
url: "http://localhost/quatro/api/submit.php",
type: 'POST',
data: formData,
success: function (response) {
}
})
}
</script>
我的 PHP 代码:
$host = "localhost";
$username = "root";
$password = "";
try {
$conn = new PDO("mysql:host=$host;dbname=quatro", $user_email, $user_pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
$response = array('success' => false);
if (isset($_POST['user_email']) && $_POST['user_email'] != '' && isset($_POST['user_pass']) && $_POST['user_pass'] != '') {
$sql = "INSERT INTO wp_users(user_email user_pass,) VALUES('" . addslashes($_POST['user_email']) . "', '" . addslashes($_POST['user_pass']) . "')";
if ($conn->query($sql)) {
$response['success'] = true;
}
}
echo json_encode($response);```
I want to add a new WordPress user to the table wp_users through HTML form but for some reason, it just doesn't work. What could be wrong? Do I need to insert other inputs? Or maybe to create a different table for this?
This is my HTML code:
<span class="bottomForm">
<p style="color:red; font-weight: bold;">
< חזרה לעגלת הקניות </p> <button class="bottomButton" type="button" onclick="submitForm()"
name="save_contact">המשך
לאפשרויות משלוח</button>
</span>
</form>
<script type="text/javascript">
function submitForm() {
var email = $('input[name=user_email]').val();
var password = $('input[name=user_pass]').val();
var formData = {
email: user_email,
password: user_pass
};
$.ajax({
url: "http://localhost/quatro/api/submit.php",
type: 'POST',
data: formData,
success: function (response) {
}
})
}
</script>
My PHP code:
$host = "localhost";
$username = "root";
$password = "";
try {
$conn = new PDO("mysql:host=$host;dbname=quatro", $user_email, $user_pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
$response = array('success' => false);
if (isset($_POST['user_email']) && $_POST['user_email'] != '' && isset($_POST['user_pass']) && $_POST['user_pass'] != '') {
$sql = "INSERT INTO wp_users(user_email user_pass,) VALUES('" . addslashes($_POST['user_email']) . "', '" . addslashes($_POST['user_pass']) . "')";
if ($conn->query($sql)) {
$response['success'] = true;
}
}
echo json_encode($response);```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论