Jump to content

Archived

This topic is now archived and is closed to further replies.

hey_suburbia

Associate "Name" field in DB with email entered.

Recommended Posts

I have a simple form that checks to see if you're email is in the DB and if so, it redirects you.

I wanted to know how to associate that email with the name field in the DB.

Something like:

[code]$fetch_exist=mysql_query("SELECT name FROM memberlist WHERE email = '$email'");

$name = $fetch_exist;[/code]

????

Would that work?

Share this post


Link to post
Share on other sites
to check the field you can do this.
[code]$select = "SELECT name FROM memberlist WHERE email = '$email';";
$query = mysql_query($select);[/code]
// that set's the foundation for it then..
[code]if (mysql_num_rows($query)) {
// if it finds something it does this.
}[/code]
or if you wanted vice versa
[code]if (!mysql_num_rows($query)) {
// if it didn't find anything it does this.
}[/code]
That is just to test them, if you wanted to have access to the database variables you have to use mysql_fetch_array or a similiar function, and use the variable name as the key like
[code]while($row = mysql_fetch_array($select)) {
// THen you access your table columns through the array.  Using there names as values like
echo $row['email'];
// that would print out the email address from the database.
}[/code]

Share this post


Link to post
Share on other sites
Thanks, that worked.
I just changed it around a little and I think you had a typo, on the [code]mysql_fetch_array($select)[/code], it should be [code]mysql_fetch_array($query)[/code]

No biggie, thanks!

[code]$select = "SELECT name FROM memberlist WHERE email = '$email';";
$query = mysql_query($select);

while($row = mysql_fetch_array($query)) {
// THen you access your table columns through the array.  Using there names as values like
$row['name'];
$name = $row['name'];
// that would print out the email address from the database.
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.