这是我第一次尝试wordpress。我将一些名称(如“name”、“e-mail”等)更改为“name1”、“email1”等。因为如果不进行这些更改,提交按钮指的是404页。
当我检查数据库时,它上没有任何注册
我不知道什么是问题的特殊代码,所以我给出了我的所有代码。如果你知道足够的信息,也许你可以很容易地解决这个问题。但若你们并没有足够的信息,你们可能会对这个问题给出否定的观点,然后离开我的问题。或者,你可以结束我的问题,写下“给我们特定的代码/问题”。我再次写信,我的问题或提问方式没有问题,这完全是你的信息。
<!-- data mata -->
<div class="reservation-info">
<form class="reservation-form" method="post">
<h2>Make a reservation</h2>
<div class="field">
<input type="text" name="name1" placeholder="Name" required>
</div>
<div class="field">
<input type="datetime-local" name="date1" placeholder="Date" step="300" required>
</div>
<div class="field">
<input type="text" name="email1" placeholder="E-Mail">
</div>
<div class="field">
<input type="tel" name="phone1" placeholder="Phone Number" required>
</div>
<div class="field">
<textarea name="message1" placeholder="Message" requires></textarea>
</div>
<div class="g-recaptcha" data-sitekey="6LeKTjMUAAAAAJuZI0qqIBRp92slJoG4SESblWHw"></div>
<input type="submit" name="reservation1" class="button" value="Send">
<input type="hidden" name="hidden" value="1">
</form>
</div>
<小时>
<?php
function lapizzeria_database(){
global $wpdb;
global $lapizzeria_db_version;
$lapizzeria_db_version = "1.0";
$table = $wpdb->prefix . \'reservations1\';
$charset_collate = $wpdb->get_charset_collate();
// SQL Statement
$sql = "CREATE TABLE $table (
id mediumint(9) NOT NULL AUTO_INCREMENT,
name1 varchar(50) NOT NULL,
date1 datetime NOT NULL,
email1 varchar(50) DEFAULT \'\' NOT NULL,
phone1 varchar(10) NOT NULL,
message1 longtext NOT NULL,
PRIMARY KEY (id)
) $charset_collate; ";
require_once(ABSPATH . \'wp-admin/includes/upgrade.php\');
dbDelta($sql);
}
add_action(\'after_setup_theme\', \'lapizzeria_database\');
<小时>
function lapizzeria_save_reservation() {
if(isset($_POST[\'reservation1\']) && $_POST[\'hidden\'] == "1") {
// read the value from recaptcha response
$captcha = $_POST[\'g-recaptcha-response\'];
// Send the values to the server
$fields = array(
\'secret\' => \'6LeKTjMUAAAAAFeaj6Hq941AFvASw9sBJjeiCDyB\',
\'response\' => $captcha,
\'remoteip\' => $_SERVER[\'REMOTE_ADDR\']
);
// Start the request to the server
$ch = curl_init(\'https://www.google.com/recaptcha/api/siteverify\');
// configure the request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
// Send the encode values in the URL
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
// Read the return value
$response = json_decode(curl_exec($ch));
if($response->success) {
global $wpdb;
$name = sanitize_text_field( $_POST[\'name1\'] ) ;
$date = sanitize_text_field( $_POST[\'date1\'] ) ;
$email = sanitize_email( $_POST[\'email1\'] );
$phone = sanitize_text_field( $_POST[\'phone1\'] ) ;
$message = sanitize_text_field( $_POST[\'message1\'] ) ;
$table = $wpdb->prefix . \'reservations1\';
$data = array(
\'name1\' => $name1,
\'date1\' => $date1,
\'email1\' => $email1,
\'phone1\' => $phone1,
\'message1\' => $message1
);
$format = array(
\'%s\',
\'%s\',
\'%s\',
\'%s\',
\'%s\'
);
$wpdb->insert($table, $data, $format );
$url = get_page_by_title(\'Thanks for your reservation!\');
wp_redirect( get_permalink($url) );
exit();
}
}
}
add_action(\'init\', \'lapizzeria_save_reservation\');
?>
<小时>
function lapizzeria_reservations() { ?>
<div class="wrap">
<h1>Reservations</h1>
<table class="wp-list-table widefat striped">
<thead>
<tr>
<th class="manage-column">ID</th>
<th class="manage-column">Name</th>
<th class="manage-column">Date of Reservation</th>
<th class="manage-column">Email</th>
<th class="manage-column">Phone Number</th>
<th class="manage-column">Message</th>
<th class="manage-column">Delete</th>
</tr>
</thead>
<tbody>
<?php
global $wpdb;
$table = $wpdb->prefix . \'reservations1\';
$reservations = $wpdb->get_results("SELECT * FROM $table", ARRAY_A);
foreach($reservations as $reservation): ?>
<tr>
<td><?php echo $reservation[\'id\']; ?></td>
<td><?php echo $reservation[\'name1\']; ?></td>
<td><?php echo $reservation[\'date1\']; ?></td>
<td><?php echo $reservation[\'email1\']; ?></td>
<td><?php echo $reservation[\'phone1\']; ?></td>
<td><?php echo $reservation[\'message1\']; ?></td>
<td>
<a href="#" class="remove_reservation" data-reservation="<?php echo $reservation1[\'id\']; ?>">Remove</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php }
?>