我在显示用户订单信息时遇到问题。我正在使用wordpress,所以不得不使用它们的功能。有一个名为表格的表格,其中包含我想要显示的所有订单信息,另一个名为wp_users的表格中包含电子邮件和用户名。电子邮件将与表单中的电子邮件相同,所以我想以某种方式试图查看表单的电子邮件和wp_users的电子邮件是否匹配,以便我可以向特定用户显示他的订单信息,但我不知道我是怎么回事会这样做。
这就是我收到订单和电子邮件信息的方式
$inputs = $wpdb->get_row("SELECT * FROM form WHERE md5(concat(ID)) = '$validate'");
if (empty($_REQUEST) || !empty($_GET['order_nr'])) {
?>
<form name="abonnement" action="/" method="post">
1 jaar abonnement: <input type = "radio" name="option" value = "1" checked = "checked"><br>
Eerst volgende nummer: <input type = "radio" name="option" value = "2"><br>
Historische nummer <input type = "radio" name="option" value = "3">
<br><br>
Naam:<input type = "text" name="naam" value = "<?php echo $inputs->naam; ?>" required><br>
Adres:<input type = "text" name="adres" value= "<?php echo $inputs->adres; ?>" required><br>
Postcode/Woonplaats:<input type="text" name = "plaats" value = "<?php echo $inputs->plaats; ?>" required><br>
Land:<input type= "text" name="land" value = "<?php echo $inputs->land; ?>"required><br>
Telefoon: <input type = "text" name="tel" value = "<?php echo $inputs->telefoon; ?>"required><br>
Email: <input type = "email" name="email" value = "<?php echo $inputs->email; ?>" required><br>
Datum: <input type = "text" name="datum" value = "<?php echo $inputs->datum; ?>" required><br><br>
<input type = "hidden" name="order_id" value = "<?php echo $inputs->ID; ?>">
<input id = "appear" type = "checkbox" name ="cadeau"> Geeft u het abonnement cadeau? Vul dan ook het onderstaande formulier in.<br>
<div id="cadeau">
Naam:<input type = "text" name = "cadNaam">
Adres:<input type = "text" name = "cadAdres">
Postcode/Woonplaats:<input type = "text" name = "cadPlaats">
Land:<input type= "text" name = "cadLand">
Telefoon: <input type = "text" name = "cadTel" >
Email: <input type = "text" name = "cadEmail"><br>
</div>
<input type = "submit" name = "formSubmit" value = "Verzenden"><br><br>
</form>
<?php
$wpdb->insert( 'form', array(
'naam' => $_POST['naam'],
'adres' => $_POST['adres'],
'plaats' => $_POST['plaats'],
'land' => $_POST['land'],
'telefoon' => $_POST['tel'],
'email' => $_POST['email'],
'datum' => $_POST['datum'],
'cadNaam' => $_POST['cadNaam'],
'cadAdres' => $_POST['cadAdres'],
'cadPlaats' => $_POST['cadPlaats'],
'cadLand' => $_POST['cadLand'],
'cadTelefoon' => $_POST['cadTel'],
'cadEmail' => $_POST['cadEmail'],
'option' => $option,
'prijs' => $priceDB,
'Tijd' => $now
));
这是我创建wordpress用户的地方
$email = $_POST['email'];
$option = $_POST['option'];
$price = "";
if( null == username_exists( $email ) ) {
$password = wp_generate_password( 12, false );
$user_id = wp_create_user( $email, $password, $email );
wp_update_user(
array(
'ID' => $user_id,
'nickname' => $email
)
);
$user = new WP_User( $user_id );
$user->set_role( 'contributor' );
wp_mail( $email, 'Welcome!', 'Your Password: ' . $password );
}
所以它可能看起来像这样吗?
$orderinfo = $wpdb->get_row("SELECT * FROM form WHERE wp_users.email = form.email");
提前致谢。
答案 0 :(得分:0)
将此查询用于相同电子邮件值的反向数据。
$orderinfo = $wpdb->get_row("SELECT * FROM wp_user inner join form on wp_users.email = form.email");
如果您需要,请在wp_user和表单中检查用户ID。
$orderinfo = $wpdb->get_row("SELECT * FROM wp_user inner join form on wp_users.email = form.email and wp_user.user_id= form.user_id");