0

I want to check whether select query is returning some values or not.

if(!empty($_POST['sign']))
{
    $e=$_POST['email'];
    $p-$_POST['password'];
    $selquery="select * from login where email_id='$e' and password='$p'";
    $r=mysql_query($selquery);
}
insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
Pia Arora
  • 11
  • 2

2 Answers2

1

To print the sql query result, do the following:

 $r = mysql_query ($selquery);
 echo '$a = $r';
Shade
  • 9,936
  • 5
  • 60
  • 85
Luv
  • 51
  • 2
0

You could use the mysql_num_rows() function to retrieve a count and see if it's larger than 0.

if (mysql_num_rows($r) > 0) {
    // do something
}

However, you really shouldn't use mysql_* functions anymore, since they will soon be deprecated. Instead, you should use PDO or mysqli!

You can read more about why not to use these functions here: Why shouldn't I use mysql_* functions in PHP?

And a comparison of PDO vs mysqli is here: http://net.tutsplus.com/tutorials/php/pdo-vs-mysqli-which-should-you-use/

Community
  • 1
  • 1
Jeroen
  • 13,056
  • 4
  • 42
  • 63
  • i edited the code but now every time it is giving invalid userif(!empty($_POST['sign'])) { $e=$_POST['email']; $p-$_POST['password']; $selquery="select * from login where email_id='$e' and password='$p'"; $r=mysql_query($selquery); if(mysql_num_rows($r) > 0) { $result=mysql_query($selquery); $row=mysql_fetch_assoc($result); $id=$row['id']; header("location:index.php?uid=$id"); } else { echo "Invalid username"; } } – Pia Arora Mar 23 '13 at 10:19