Jump to content

Need Help php code to look up username based on email address.


funkymonkey

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<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!';
    }
}
?>

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.