KillZoneZ Posted August 27, 2015 Share Posted August 27, 2015 (edited) I want to make it check the database for an equal value to the one inputed by the user and if so echo a sentence saying it is already registered, and if it is not, it would just insert the data into the database table. Here's my code: <?php $servername = "***"; $username = "***"; $password = "***"; $dbname = "a3108948_evorpg"; $Mail = $_POST['email']; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $Mail = $_POST['email']; $MailInsert = $dbname->query("INSERT INTO betakey (Mail) VALUES ($Mail)"); $SearchEmail = $dbname->query("SELECT (Mail) FROM betakey WHERE Mail = $Mail"); if ($SearchEmail->num_rows > 0) { echo "That Email is already registered for the closed alpha"; } else { } $conn->close(); ?> This is the error i get: Fatal error: Call to a member function query() on a non-object in /home/a3108948/public_html/BetaRegistration.php on line 27 Edited August 27, 2015 by KillZoneZ Quote Link to comment Share on other sites More sharing options...
Barand Posted August 27, 2015 Share Posted August 27, 2015 $email is a string value and therefore needs to be in single quotes in your queries "INSERT INTO betakey (Mail) VALUES ('$Mail')" "SELECT (Mail) FROM betakey WHERE Mail = '$Mail' " It would make more sense to do the check with the SELECT query before inserting. You could just use the INSERT query if you define email as unique and do away with the select. Then, if you get a duplicate key error, you know it already existed. Quote Link to comment Share on other sites More sharing options...
KillZoneZ Posted August 27, 2015 Author Share Posted August 27, 2015 (edited) I added the quotes and it is still not working. Same error. The error refers to line 27: $MailInsert = $dbname->query("INSERT INTO betakey (Mail) VALUES ('$Mail')"); And it says Call to a member function query() on a non-object Edited August 27, 2015 by KillZoneZ Quote Link to comment Share on other sites More sharing options...
maxxd Posted August 27, 2015 Share Posted August 27, 2015 $dbname is undefined. You connect to the database using $conn, then try to run a db transaction using $dbname. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.