funkymonkey Posted February 12, 2008 Share Posted February 12, 2008 Hi all, I'm an accounting student working on an IT manager bachelors degree. The course I am working on is Database management for Financial Managers. The question I am working on deals with php code, but in the text they never really talk about php but they give some example code used to accept user input to register for a course. The code they show is divided into 3 parts (1) PHP script initiation and input validation (starts with HTML code to setup generic page, checks wether to process form, and parts to validate all require fields) (2) Adds user info to database and (3)Closes php script and displays html form. Using this example I am suppose to write a script that accepts a e-mail address as the input, queries the database with the e-mail address value, and returns for display the associated username. I am totally lost. Can anyone provide some help? Quote Link to comment https://forums.phpfreaks.com/topic/90587-need-help-php-code-to-look-up-username-based-on-email-address/ Share on other sites More sharing options...
trq Posted February 12, 2008 Share Posted February 12, 2008 I suggest you read over the examples again. Short of us doing it for you, I can't see why our examples would be any clearer. The process is simple. A form posts an email address to a php script. In your script you will find the email address within the $_POST array. Put it into an sql statement (string). You then execute that sql statement via mysql_query which returns a result resource containing the user name your after. Quote Link to comment https://forums.phpfreaks.com/topic/90587-need-help-php-code-to-look-up-username-based-on-email-address/#findComment-464477 Share on other sites More sharing options...
Stooney Posted February 12, 2008 Share Posted February 12, 2008 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="text" name="email"> <input type="submit" value="Search"> </form> <?php if(isset($_POST['email']) && strlen($_POST['email'])>0){ $email=mysql_real_escape_string($_POST['email']); $check=mysql_query("SELECT username FROM tablename WHERE email='$email'"); if(mysql_num_rows($check)==1){ $email=mysql_fetch_array($check); echo 'Email: '.$email[0]; } else{ echo 'No results found!'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90587-need-help-php-code-to-look-up-username-based-on-email-address/#findComment-464482 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.