Fatal Error: Call To A Member Function Fetch_Assoc() On A Non-Object

CattleyaJohnson

New Member
I am trying to create a small form for people to come to my website and simply enter the following information:
  • Name
  • Surname
  • Email Address
It should send this information back into my table from my database.Now here is where things get "complex" (...well it is to me, okay? )If the email address does exist in our table, then it must echo "Email Address Added. Thank you!". Otherwise if it does NOT exist, then it must echo "Email address already exists!"For some reason it is not doing this. It is spitting out this error:\[code\]Fatal error: Call to a member function fetch_assoc() on a non-object in C:\wamp\www\addemail.php on line 46\[/code\]I have attached my php code (below):\[code\]<!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 = "http://stackoverflow.com/questions/12746204/newsletter_frame.html"; }//--></script><!-- This is the link to the external CSS file--><link rel="stylesheet" type="text/css" href="http://stackoverflow.com/questions/12746204/css/mystyle.css"><!-- This is the link to the external Javascript file--><script type="text/javascript" src="http://stackoverflow.com/questions/12746204/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>\[/code\]
 
Back
Top