Question

I'm new to php/mysql and I'm wondering how i would accomplish a "forgot my password" page that displays the question the user filled out during the registration.

I've got a query but I can't seem to get it to work

$emailcheck = $_POST['email'];
$checkit = mysql_query("SELECT * Security_Question FROM users WHERE email ='$emailcheck'")

so my question is how would i display "Security Question"?

Was it helpful?

Solution

use the mysql_fetch_array() method to extract the data from your query resource:

$emailcheck = $_POST['email'];
$checkit = mysql_query("SELECT Security_Question FROM users WHERE email ='$emailcheck'"); //fixed query syntax*
if (!$checkit) exit(); //don't forget to catch query errors!
$result = mysql_fetch_array($checkit);
$question = $result['Security_Question'];

$question will hold the security question.

OTHER TIPS

Your SQL is incorrect.

$checkit = mysql_query("SELECT Security_Question FROM users WHERE email ='$emailcheck'");

or

$checkit = mysql_query("SELECT * FROM users WHERE email ='$emailcheck'");

You shouldn't be using a POSTed variable directly in your SQL either. Atleast santize it first, or mysql escape it. Better yet try using prepared statements,

http://php.net/manual/en/pdo.prepared-statements.php
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top