php - 将自定义表单中的数据保存在 wordpress 数据库中
问题描述
我创建了一个 PHP 程序,它根据在 HTML 联系表单中输入的用户输入提供自定义输出。HTML 表单和 PHP 输出工作正常。但是,当我尝试将数据保存在 WP 数据库中时,我看不到任何响应。我没有在表单操作中插入任何主题目录位置以使 $region 值能够以 php 形式处理(如果我正在插入主题文件,程序会在提交时重定向到该 URL)。请让我知道如何将用户输入保存在数据库中。请在下面找到代码:
<?php
$region = $_POST['Region'];
$Click_here_to_start_your_download = 'https://mydailysugar.info/wp-content/uploads/2019/09/Blood-Glucose-Chart-A4-1.pdf';
switch ($region) {
case 'North':
echo "<a href='$Click_here_to_start_your_download'>Click here to start your download</a>";
die;
case 'South':
echo "<a href='$Click_here_to_start_your_download'>Click here to start your download</a>";
die;
case 'East':
echo "<a href='$Click_here_to_start_your_download'>Click here to start your download</a>";
die;
case 'West':
echo "<a href='$Click_here_to_start_your_download'>Click here to start your download</a>";
die;
}
$name = $_POST['user_name'];
$email = $_POST['user_email'];
$phone = $_POST['user_phone'];
function insertuser($name, $email, $phone) {
global $wpdb;
$table_name = $wpdb->prefix . 'mealplanner';
$wpdb->insert($table_name, array
('user_name' => $name, 'user_email' => $email, 'user_phone' => $phone)
);
}
insertuser($name, $email, $phone);
?>
<html>
<head>
<title> Meal Planner </title>
</head>
<body>
<form method='POST'>
<p>Name</p> <input type='text' name='user_name'>
<p>Email</p> <input type='text' name='user_email'>
<p>Phone</p> <input type='text' name='user_phone'>
<p>Dropdown Box</p>
<select name='Region' size='1'>
<option value='North'>North
<option value='South'>South
<option value='East'>East
<option value='West'>West
</select>
<br/>
<input type='submit' value='SUBMIT'><input type='reset' value='CLEAR'>
</form>
</body>
</html>
解决方案
推荐阅读
- apache-spark - 火花数据框将字符串列转换为具有给定格式的时间戳
- applescript - 通过 AppleScript 从 iMessage 发送 GIF
- security - 使用 fluentd 和 ELK 的 Kubernetes pod 日志
- android - android studio中的动态布局定位
- python - 熊猫中的日期时间毫秒到秒
- cucumber - Cucumber 特征文件 - 描述聚合
- android - AAPT2 aapt2-3.2.1-4818971-windows 守护进程 #0
- php - 如何在 Laravel Passport Api 中集成 reCaptcha?
- python - Python - 从当前文件中获取自定义模块
- java - Java将列表的1/3个元素复制到新创建的三个列表中