当我尝试从我的函数添加记录时,我收到此错误 有什么建议可以解决这个问题吗?
PHP Fatal error: Call to a member function insert() on a non-object
我的功能是这个
function setdb($email){
global $wpdb;
$set_mail=$email;
$table_name = $wpdb->prefix . 'nd_tempemails';
$result=$wpdb->insert(
$table_name,
array('email'=>$set_mail
)
);
}
*编辑由于请求,我添加了我的整个php代码.在这里我发送了一个链接,为此我保留了我发送链接的电子邮件作为记录。
function sendmail()
{
$email = $_POST['email'];
$passmail=md5($email);
$subject = 'The Registration Link';
$headers = "From: xxx@xxx.xx ". "'r'n";
$headers .= "Reply-To: xxx@xxx.xx" . "'r'n".
$headers .= "MIME-Version: 1.0'r'n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1'r'n".'X-Mailer: PHP/' . phpversion();
$message = 'Here is your One time URL<br>';
$message.="<a href='link";
$message.=$passmail;
$message.="'>click here</a>";
mail($email, $subject, $message, $headers);
setdb($passmail);
}
if(isset($_POST['email']))
{
sendmail();
}
所有函数都在同一个文件中。
试试这个
function setdb($email){
global $wpdb;
$table_name = $wpdb->prefix.'nd_tempemails';
$result=$wpdb->insert(
$table_name,
array('email'=>$email)
);
}
Call setdb('xyz@xyz.com');
好的,
我通过直接调用 wordpress 配置文件并使用默认的 mysqli
命令解决了这个问题。我试图包含 wp-db.php 并完成此操作,但没有奏效。