这似乎很容易,但我被困在某个地方。 我试图查看用户何时注册该电子邮件是否已经在数据库中,简单。
HTML:
<form class="reg-page" name="register" action="<?php qsmp_register( $_POST['qsmp_name'],
$_POST['qsmp_email3'],
$_POST['qsmp_password3'],
$_POST['qsmp_terms'],
$_POST['qsmp_newsletter']) ?>" method="post">
<div class="reg-header">
<h2>Register a new account</h2>
</div>
<label>Name <span class="color-red">*</span></label>
<input type="text" class="form-control margin-bottom-20" size="100" name="qsmp_name" required>
<label>Email Address <span class="color-red">*</span></label>
<input type="email" class="form-control margin-bottom-20" name="qsmp_email3" required>
<div class="row">
<div class="col-sm-6">
<label>Password <span class="color-red">*</span></label>
<input size="20" type="password" class="form-control margin-bottom-20" name="qsmp_password3" required>
</div>
<div class="col-sm-6">
<label>Confirm Password <span class="color-red">*</span></label>
<input size="20" type="password" class="form-control margin-bottom-20" required>
</div>
</div>
<hr>
<div class="row">
<div class="col-lg-6">
<label class="checkbox">
<input type="checkbox" name="qsmp_terms" required>
I read <a href="http://www.braziliansocialdance.co.uk/terms/" class="color-green">Terms and Conditions</a>
</label>
<label class="checkbox">
<input type="checkbox" checked="true" name="qsmp_newsletter">
Sign up newsletter
</label>
</div>
<div class="col-lg-6 text-right">
<button class="btn-u" type="submit" name="register">Register</button>
</div>
</div>
</form>
PHP(在fucntions.php中):
$table_name = $wpdb->prefix . 'qsmp_mails';
$query = $wpdb->prepare( "SELECT COUNT(*) FROM %s WHERE email = %s ", $table_name, $mail );
echo $query;
$cEMAIL = $wpdb->get_var( $query );
echo $cEMAIL ;
if ($cEMAIL < 1 && !empty($mail))
{
但它不起作用,任何人都知道为什么? 提前谢谢!
答案 0 :(得分:1)
永远不应该直接调用wpdb()类中的方法。您需要首先使用全局$ wpdb对象(有关更多信息,请阅读Class Reference/wpdb)。
在你的functions.php中试试这样的事情:
global $wpdb;
$query->query_where .= $wpdb->prepare( " AND $wpdb->users.email = %s", $mail ); // where $mail should be the user email you are looking for
echo $query;
$cEMAIL = $wpdb->get_var($query);
echo $cEMAIL ;