$resultnx = mysql_query("SELECT * FROM `emails` WHERE `email` = '{$email}'");
$num_rows = mysql_num_rows($resultnx);
gets this warning Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ....
$resultnx = mysql_query("SELECT * FROM `emails` WHERE `email` = '{$email}'");
$num_rows = mysql_num_rows($resultnx);
gets this warning Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ....
Looks like there is some error in your query, use the die
to see what error it is:
$query = "SELECT * FROM `emails` WHERE `email` = '{$email}'";
$resultnx = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($resultnx);
Also, check to make sure that $email
is coming through fine:
var_dump($email);
Or try
$query = "SELECT * FROM `emails` WHERE `email` = '".$email."'";
$resultnx = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($resultnx);
Try outputting the contents of $query
and then pasting it into some query execution tool.
This doesn't answer your question directly, but there are probably better ways to check for duplicates. Consider modifying the email field to be unique. From your mySQL command line (or PHPMyAdmin) do the following:
ALTER TABLE `emails` ADD UNIQUE(`email`);
Now if you try to insert a row where the email already exists it will throw an error for you all on its own.
i think remove curly braces from $email
$query = "SELECT * FROM emails
WHERE email = '$email'";
$resultnx = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($resultnx);
The error you are receiving directly
MySQL server has gone away
is definitely caused by the MySql server being down. If the MySql Server and the PHP script are on the same VPS, then you are going to need to hunt down exactly what is causing the database to shut down (crash). Check the server error logs. They should tell you what the problem is.
Instead of performing the query the way you have written, why don't you simply do the following query instead:
$query = "SELECT count(*) FROM `emails` WHERE `email` = '".$email."'";
That way you can just pull the number of rows rather than all the data which runs quite a bit faster on MySql (especially if email
is indexed).
$query = "SELECT count(*) FROM `emails` WHERE `email` = '".$email."'";
$resultnx = mysql_query($query) or die(mysql_error());
$num_rows_array = mysql_fetch_array($resultnx);
$num_rows = $num_rows_array[0];
Lines in the code can be combined. They were separated to make it easier to see what was occurring.