0

I am getting users to enter their email and passwords, and with those details I wish to echo their username from the table. This is so I can demonstrate that I have retrieved a value from the table.

I do know that my query works on phpmyadmin and that the email and password is being retrieved in my php as well. The error I am getting with my current code is HTTP Error 500:

mysql_connect($database,$username,$password);
@mysql_select_db($username) or die ("Unable to select database");

$email = mysql_escape_string ($_POST['email']);
$password = mysql_escape_string ($_POST['password']);
$email = stripslashes($email);
$password = stripslashes($password);
$email = mysql_escape_string($email);
$password = mysql_escape_string($password);


$SQL = "SELECT Name FROM users WHERE BINARY Email = '$email' and BINARY password = '$password'";

$result = mysql_query($SQL) or die("Unable to Run Query");

$value = mysql_fetch_object($result) or die("Unable to Fetch Object");

echo "<h2>$value</h2>" or die("Unable to Echo");
  • 1
    If you have the appropriate access, you may be able to assist yourself by enabling error reporting for PHP. display_errors = on shouold be added to your PHP.ini file. http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – Stese Apr 12 '17 at 11:04
  • Maybe can help https://www.lifewire.com/500-internal-server-error-explained-2622938 – b2ok Apr 12 '17 at 11:08

3 Answers3

0

Change the statment to

$SQL = "SELECT Name FROM users WHERE BINARY Email = '".$email."' and BINARY 
        password = '".$password."'";
Nishant Nair
  • 1,999
  • 1
  • 13
  • 18
0

First of all do not use mysql_*, as they are deprecated. You can achieve this like:

$result = mysql_query($SQL);
if( mysql_num_rows($result) > 0 )
{
    $data = mysql_fetch_assoc($result);
    // $data is an array, to return a single value, do it like $data['name']
}
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
0

You should really abandon the old mysql connector and switch to MySQLi.

However, you should take a look at mysql_result()

apocs
  • 30
  • 5