Jump to content

Retrive data from drop down box via mysql


avo

Recommended Posts

HI All

Wounder if you can help me solve this one please .

what im doing is calling the db and retriving data from it and displaying it .This is the code bellow

[code]

if($_POST['subEdit']){
    mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($dbname);
    $sql = mysql_query("SELECT username ,name ,lname, waddress, pnumber, mnumber, email, ainfo, dateinfo FROM memlist WHERE  username=buster");               
    }
    while($result = mysql_fetch_array($sql))
    {
    $username =  "" .$result["username"];
    $name =  "" .$result["name"];
    $lname =  "" .$result["lname"];
    $waddress =  "" .$result["waddress"];
    $pnumber =  "" .$result["pnumber"];
    $mnumber =  "" .$result["mnumber"];
    $email =  "" .$result["email"];
    $ainfo =  "" .$result["ainfo"];
    $dateinfo =  "" .$result["dateinfo"];

[/code]

But this bit of the code (buster )i would like it to point at a drop down box so when i select a user from the drop down this is then iserted into this section me clicking th button will then result in the code execution with the selected name from the dropdoown box.

[code]

buster

dateinfo FROM memlist WHERE  username=[quote]buster[/quote]");        
[/code]

my drop down table
in HTML

[code]
          </select>
        <select name="select">
          <option>gavin</option>
          <option>buster</option>
          <option>mark</option>
        </select>
[/code]

Thanks in Advance
Link to comment
Share on other sites

HI thanks for getting back to me

what i have is a pull down list on my page ive added names to that list when i select one of them names i want that name to apper as ive i have typed it in the code (in place of buster)

[code]
    $sql = mysql_query("SELECT username ,name ,lname, waddress, pnumber, mnumber, email, ainfo, dateinfo FROM memlist WHERE  username=buster");
[/code]

then this will give me the results i need

at the moment for example if i type the name buster in it will get the information i need from the db

hope i explaned ok


thanks again
Link to comment
Share on other sites

So what you want is the drop down box full of names on your page. When you select the name from the drop down you want it to display all their information that is in the database correct? If that is hat you want to do; try something like this;

[code]if($_POST['subEdit']){
    mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($dbname);
    $user=$_POST['user'];
    $sql = mysql_query("SELECT username ,name ,lname, waddress, pnumber, mnumber, email, ainfo, dateinfo FROM memlist WHERE  username='$user'");                
    
    while($result = mysql_fetch_array($sql))
    {
    $username =  $result['username'];
    $name =  $result['name'];
    $lname = $result['lname'];
    $waddress = $result['waddress'];
    $pnumber = $result['pnumber'];
    $mnumber = $result['mnumber'];
    $email =  $result['email'];
    $ainfo =  $result['ainfo'];
    $dateinfo =  $result['dateinfo']; }  }[/code]

Have your form do this;

[code]
        <select name="user">
          <option>gavin</option>
          <option>buster</option>
          <option>mark</option>
        </select>[/code]

That should be a simple way to get what you want. Of course you will still have to format the output of the above script the way you want it, but that should be simple.

If I'm not mistaken I don't believe you need all thos "" and . up there either when you are setting the variables.
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.