Jump to content


Photo

Associate "Name" field in DB with email entered.


  • Please log in to reply
2 replies to this topic

#1 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 10 August 2006 - 07:46 PM

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:

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

$name = $fetch_exist;

????

Would that work?



#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 August 2006 - 07:51 PM

to check the field you can do this.
$select = "SELECT name FROM memberlist WHERE email = '$email';";
$query = mysql_query($select);
// that set's the foundation for it then..
if (mysql_num_rows($query)) {
// if it finds something it does this.
}
or if you wanted vice versa
if (!mysql_num_rows($query)) {
// if it didn't find anything it does this.
}
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
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.
}

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 10 August 2006 - 08:18 PM

Thanks, that worked.
I just changed it around a little and I think you had a typo, on the
mysql_fetch_array($select)
, it should be
mysql_fetch_array($query)

No biggie, thanks!

$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.
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users