Jump to content

Why doesn't this work?


KillZoneZ

Recommended Posts

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 by KillZoneZ
Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

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 by KillZoneZ
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.