Jump to content

Associate "Name" field in DB with email entered.


hey_suburbia

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?

Link to comment
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]
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.