我正在尝试为人们创建一个小表单来访问我的网站,只需输入以下信息:
- 姓名
- 姓
- 电子邮件地址
它应该将此信息从我的数据库发送回我的表中。
现在这就是事情变得“复杂”的地方(......对我来说,好吗?)
如果电子邮件地址确实存在于我们的表中,则它必须回显“已添加电子邮件地址。谢谢!”。否则,如果它不存在,那么它必须回显“电子邮件地址已存在!”
由于某种原因,它没有这样做。它吐出这个错误:
Fatal error: Call to a member function fetch_assoc() on a non-object in C:\wamp\www\addemail.php on line 46
我附上了我的php代码(如下):
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<script LANGUAGE="JavaScript">
<!--
function redirect () { setTimeout("go_now()",3000); }
function go_now () { window.location.href = "newsletter_frame.html"; }
//-->
</script>
<!-- This is the link to the external CSS file-->
<link rel="stylesheet" type="text/css" href="css/mystyle.css">
<!-- This is the link to the external Javascript file-->
<script type="text/javascript" src="js/myjs.js"></script>
<title>Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="verify-v1" content="gDSxHR1Tk8vWtty9GoRHABGFEH+Bh2VHYCHv0Cx1/Ek=">
<meta name="copyright" content="Burger man">
<meta name="keywords" content="afro, afrodeep, soulful, funky, deep, vocal house, broken beats, disco">
<meta name="description" content="Burgers and chips">
<meta name="page-type" content="Information">
</head>
<body onLoad="redirect()" id="iframe_newsl_spec">
<?php
$dbc = mysqli_connect('localhost', 'root', '', 'si_store') or die('Error connecting to MySQL server.');
if ( isset($_POST['email_address']) && isset($_POST['firstname']) && isset($_POST['surname']) )
{
$email_address = $_POST['email_address'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$query = mysqli_query("SELECT * FROM email_list WHERE email_address = '$email_address'");
if ( mysql_num_rows($query) > 0)
{
echo 'Email address already exists!';
}
else
{
mysqli_query("INSERT INTO email_list(email_address, firstname, surname) VALUES ('$email_address','$firstname','$surname')");
echo 'Email Address Added. Thank you!';
}
}
//mysqli_query($dbc, $query) or die ('Error connecting to database.');
mysqli_close($dbc);
?>
</body>
</html>