SELECT record from user selection from dropdown box - noobie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
katkat
Forum Newbie
Posts: 23
Joined: Tue Mar 03, 2009 9:50 pm

SELECT record from user selection from dropdown box - noobie

Post by katkat »

Really struggling on this one:

I populate a dropdown box with a list of first and last names from a database. The user finds his name and selects it, then presses a "submit" button. This part works.

I want to get that record from the database by matching the unique key associated with that record but I am not sure how to get it. Then I display all the fields in a form so he can update his information, which I will write back to the database when he presses a "Update" button.


// Creates the drop down list
$result = mysql_query("SELECT * FROM runners");
echo "<select name='fullname'>";

while($list = mysql_fetch_array($result, MYSQL_ASSOC))
echo "<option value=$runnerid[runnerid]>$list[firstname] $list[lastname]</option>";
echo '&nbsp<input type="submit" value="select" name="submit">';

// Get specific record

if (isset ($_GET['select'])) {
$firstname = $_GET['firstname'];
$lastname = $_GET['lastname'];

$query = "SELECT * FROM runners WHERE runnerid='$runnerid'";
$result=mysql_query($query);

Thanks!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: SELECT record from user selection from dropdown box - noobie

Post by Benjamin »

Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
amit_n
Forum Newbie
Posts: 9
Joined: Sat Mar 07, 2009 12:19 am

Re: SELECT record from user selection from dropdown box - noobie

Post by amit_n »

On submit try to echo $_GET['fullname']
Post Reply