0

I am taking email input from users and storing it in database and I want to avoid duplicate entry. The code I am currently using giving me Deprecated: mysql_query() and mysql_num_rows() expects parameter 1 to be resource Warnings and executing else part of the program please anyone correct my mistake here

$value = $_POST['input1'];
$query = mysql_query("SELECT * FROM savedemail WHERE email='$value'");
if(mysql_num_rows($query) > 0)
{
echo "Username already exists";
}
else{
echo "else-part";
}
$conn->close();
Patrick Q
  • 6,373
  • 2
  • 25
  • 34
  • 2
    (1) The `mysql_*` library *is* deprecated. Use `mysqli` or `PDO` instead. (2) The query is failing. The code *assumes* the query succeeds and never checks for an error. However, there's an error. (3) It could be failing for any number of reasons, since it's wide open to SQL injection and you're basically executing any code your users give you. – David Feb 10 '16 at 20:01
  • It's impossible to get that error message on mysql_query(). query expects a **STRING** for parameter 1, and most of the mysql_*() functions expect a resource as the SECOND argument. given the `$conn->close` at the end, you're very obviously mixing mysql apis, and this is just a dupe. – Marc B Feb 10 '16 at 20:02
  • Use yur query in phpmyadmin SELECT * FROM savedemail WHERE email='yourvalue' .... Chk how many rows fetched – devpro Feb 10 '16 at 20:04
  • @devpro its showing the desired row in phpmyadmin. But how to make it work with my php code –  Feb 10 '16 at 20:06
  • Did u read this Deprecated: mysql_query() ??? – devpro Feb 10 '16 at 20:09
  • Please use mysqli or PDO – devpro Feb 10 '16 at 20:10

0 Answers0