PHP Help?

I need help with something. I can’t think of a way to code this using PHP.

I have a row that holds first name, email, and password. All I know is their email and password, and it is stored under $ep.

Is there a way to find the first name associated with the row that the email and password is on? If so, how?

Hi,

wow, that was vague.
So you have an ( I assume ) array named $ep ?
It holds name, password and email…
I imagine:
[php]
$ep = array(
array( ‘name’ => ‘somename’,
‘email’ => ‘[email protected]’,
‘password’ => ‘XXXXXXXX’ ),
array( ‘name’ => ‘othername’,
‘email’ => ‘[email protected]’,
‘password’ => ‘XXXXYXXX’ ),
/* ( &c. ) */
);
[/php]

and from that point I have no clue what you’re trying to do.
You have the password and email and want to find in what ‘record’ that is?

Assume you have the password in $password and the email in $email,
that would look like:
[php]
foreach ( $ep as $eprow )
{ if ( $eprow[‘email’] == $email &&
$eprow[‘password’] == $password )
{ echo $eprow[‘name’];
}
}
[/php]

Is that what you were looking for?
If not, I’d really advise you to try and restate the question.

Good luck! =D
O.

[php]
$email="{$ep[‘email’]}";
$password="{$ep[‘password’]};
mysql_query(“SELECT first name FROM tablename WHERE email = ‘$email’ AND password = ‘$password’”);
[/php]

Thanks. I have a question. Wouldn’t selecting first name, but checking in the email and password not work? It doesn’t work…

Sorry I was so vague. Here is a source code (after session_start(); and the connecting code)

[php]$email = $_POST[‘email’];
$password = $_POST[‘password’];
$password2 = hash(“sha512”, $password);

$ep = mysql_query(“SELECT * FROM persons WHERE email=$email AND password=$password2”);

if(mysql_num_rows($ep) == 0) {
header(‘Location: wrong-login.php’);
exit();
}
mysql_query(“SELECT firstname AND lastname FROM persons WHERE email=$email AND password=$password2”);
$_SESSION[‘email’] = $email;
$_SESSION[‘firstname’];
$_SESSION[‘lastname’];
header(‘Location: main-index.php’);
exit();

?>[/php]

Your queries are error’d. In the email=$email AND password=$password2 parts, replace the ` symbols, with an apostrophe: ’

You can’t use $ep as you have it, you need more code
[php]
$email = mysql_real_escape_string($_POST[‘email’]);
$password = hash(“sha512”, $_POST[‘password’]);

$ep = mysql_query(“SELECT * FROM persons WHERE email=’$email’ AND password=’$password’”);

if(mysql_num_rows($ep) == 0) {
header(‘Location: wrong-login.php’);
} else {
$r = mysql_fetch_assoc($ep);
$_SESSION[‘email’] = $email;
$_SESSION[‘firstname’] = $r[‘firstname’];
$_SESSION[‘lastname’] = $r[‘lastname’];
header(‘Location: main-index.php’);
}
?>[/php]

[size=14pt]UPDATE:[/size] I fixed it. I used mysql_fetch_row and it worked out fine.

Sponsor our Newsletter | Privacy Policy | Terms of Service