Php 致命错误:对非对象调用成员函数Fetch_Assoc()

Php 致命错误:对非对象调用成员函数Fetch_Assoc(),php,html,mysql,phpmyadmin,Php,Html,Mysql,Phpmyadmin,我正在尝试创建一个小表单,供人们访问我的网站,只需输入以下信息: 名字 姓 电子邮件地址 它应该将这些信息从我的数据库发送回我的表中 现在事情变得“复杂”(…对我来说是这样,好吗?) 如果电子邮件地址确实存在于我们的表中,那么它必须回显“已添加电子邮件地址。谢谢!”。否则,如果它不存在,则必须回显“电子邮件地址已存在!” 出于某种原因,它没有这样做。它指出了这个错误: Fatal error: Call to a member function fetch_assoc() on a non-

我正在尝试创建一个小表单,供人们访问我的网站,只需输入以下信息:

  • 名字
  • 电子邮件地址
它应该将这些信息从我的数据库发送回我的表中

现在事情变得“复杂”(…对我来说是这样,好吗?)

如果电子邮件地址确实存在于我们的表中,那么它必须回显“已添加电子邮件地址。谢谢!”。否则,如果它不存在,则必须回显“电子邮件地址已存在!”

出于某种原因,它没有这样做。它指出了这个错误:

Fatal error: Call to a member function fetch_assoc() on a non-object in C:\wamp\www\addemail.php on line 46
我已附上我的php代码(如下所示):


一旦您修复了
mysql\u*
函数,并将其更改为
mysqli\u*
,并且您已经更改了代码以便使用准备好的语句,您应该添加以下代码:

$stmt = mysqli_prepare('SELECT * FROM email_list WHERE email_address = ?');
//BTW, if all you want to check if a record exists, don't use SELECT *
//Just select one field, not the entire row
mysqli_stmt_bind_param($stmt,'s',$_POST['email_address']);
//bind param, to statement, as String, value ^^
mysqli_stmt_execute($stmt);
//execute the query
mysqli_stmt_bind_result($stmt,$col1,$col2,$col3);
//bind variables that will be assigned the value of the fields
while(mysqli_stmt_fetch($stmt))
{//get the values in question
    echo 'col1: '.$col1.'<br/>col2: '.$col2.'<br/>col3: '.$col3.'<br/>';
}
$stmt=mysqli\u prepare('从电子邮件地址=?'的电子邮件列表中选择*);
//顺便说一句,如果您只想检查记录是否存在,请不要使用SELECT*
//只选择一个字段,而不是整行
mysqli_stmt_bind_param($stmt,'s',$\u POST['email_address');
//绑定参数,到语句,作为字符串,值^^
mysqli_stmt_execute($stmt);
//执行查询
mysqli_stmt_bind_result($stmt、$col1、$col2、$col3);
//绑定将分配字段值的变量
while(mysqli_stmt_fetch($stmt))
{//获取有问题的值
回显“col1:”.$col1.
col2:“.$col2.
col3:”.$col3.
”; }

要获得结果集的关联数组,您需要使用几个函数。

您在做什么<代码>mysql*
还是
mysqli*
?选择一个我不知道我在看什么。您的mysql\uU0()和mysqli\uU0()组合不兼容,并且没有调用mysqli::fetch\u assoc()。请尝试将mysqli\u num\u行更改为mysqli\u num\u行。注意:在mysqli上使用mysqli的原因(您没有这样做)是准备好的语句:是的,
mysqli\uU0*
是健全的第一步,但没有准备好的语句,Bobby Tables仍然会有很多乐趣
$stmt = mysqli_prepare('SELECT * FROM email_list WHERE email_address = ?');
//BTW, if all you want to check if a record exists, don't use SELECT *
//Just select one field, not the entire row
mysqli_stmt_bind_param($stmt,'s',$_POST['email_address']);
//bind param, to statement, as String, value ^^
mysqli_stmt_execute($stmt);
//execute the query
mysqli_stmt_bind_result($stmt,$col1,$col2,$col3);
//bind variables that will be assigned the value of the fields
while(mysqli_stmt_fetch($stmt))
{//get the values in question
    echo 'col1: '.$col1.'<br/>col2: '.$col2.'<br/>col3: '.$col3.'<br/>';
}