我正在尝试将表单数据从自制表单发送到我的 WordPress 数据库。
我有以下代码,但我在数据库表中没有数据。怎么了?
我已经尝试添加一些 echos 和 var_export 来检查数据,但是当我单击提交站点重新加载时,我看不到 echo 或 var_export。所以很难解决这个问题。
我的网站没有给我任何错误,一切正常,但没有数据到达我的 WordPress 数据库。
在这段代码中发送的邮件看起来也像这样:“Es wurde ein neues Projekt angelgt , , , , , , ,”
所以我认为 POST 值没有从公式中给出到我的代码的其余部分。
<?php
<?php
if ( isset( $_POST['submit'] ) )
{
$wpdb->show_errors();
/* Template Name: CustomPageT1 */
$vorname = $_POST['field_vorname'];
$name = $_POST['field_name'];
$email = $_POST['field_email'];
$phone = $_POST['field_phone'];
$region = $_POST['field_hilsorganisation'];
$name = $_POST['field_bezeichnung'];
$email = $_POST['field_beschreibung'];
$phone = $_POST['field_bild'];
//Send Mail
$email = $_POST["field_email"];
$to = "erdtmann@it-ce.de";
$subject = "Neues Projekt wurde angelegt";
$headers = "From: info@rescue-deutschland.de\n";
$message = "Es wurde ein neues Projekt angelgt $field_vorname, $field_name, $field_email, $field_phone, $field_hilsorganisation, $field_bezeichnung, $field_beschreibung";
$user = "$email";
mail($to,$subject,$message,$headers);
//Insert Data To Database
global $wpdb;
$table ='wp_projekte';
$data = array(
'field_vorname' => $_POST['field_vorname'],
'field_name' => $_POST['field_name'],
'field_email' => $_POST['field_email'],
'field_phone' => $_POST['field_phone'],
'field_hilsorganisation' => $_POST['field_hilsorganisation'],
'field_bezeichnung' => $_POST['field_bezeichnung'],
'name' => $_POST['user_name'],
'field_beschreibung' => $_POST['field_beschreibung'],
'field_bild' => base64_encode(file_get_contents($_POST['field_bild'])));
var_export($data);
$format = array('%s','%s','%s','%s','%s','%s','%s','%s','%s');
$wpdb->insert( $table, $data, $format );
$wpdb->print_error();
}
?>
<html>
<head>
<title> Projekte </title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<label>Vorname</label> <input type='text' name='field_vorname'> <br/>
<label>Name</label> <input type='text' name='field_name'> <br/>
<label>E-mail</label> <input type='text' name='field_email'> <br/>
<label>Telefon</label> <input type='text' name='field_phone'> <br/>
<label>Hilfsorganisation</label> <input type='text' name='field_hilsorganisation'> <br/>
<label>Projektbezeichnung</label> <input type='text' name='field_bezeichnung'> <br/>
<label>Projektbeschreibung</label> <textarea type='text' name='field_beschreibung'></textarea> <br/>
<label>Bild für Projekt</label> <span class="wpcf7-form-control-wrap file-894"> <br/> <br/>
<input type="file" name="field_bild" size="40" class="wpcf7-form-control wpcf7-file wpcf7-validates-as-required" accept=".png,.jpg" aria-required="true" aria-invalid="false"></span>
<br/>
<br/>
<input type='submit' name ='submit' value='submit'>
</form>
</body>
</html>