All,
I am learning PHP and MySQL on the fly so if my question shows I don't know what I am doing, it's because I don't. Any help is appreciated.
I have set up a registration database for my kids little league (baseball). I can collect data (name, age, address etc) in the form and post it to the db. I can recall the data edit and repost. Everything works as it is supposed to except one field.
I have a field for parents to volunteer. I use a list select with hard coded choices (coach, asst coach, team mom etc.). It posts fine. But when retrieving for editing how do I get the value of the db field to be the item selected in the list?
thanks
10 2478
Run an UPDATE query on your table with the relevant information. I assume you're POSTing the data. -
UPDATE `tbl_name` SET `col_1` = '$col_1' WHERE `userid` = $userid;
-
Obviously you need to set the values of $col_1 and $userid, and also change the tbl_name and col_1 identifiers.
I was not clear.
Original posting and updating works great. My problem is populating the form when editing. All fields show up correct except one.
The field is filled by use of a list box. When the record updates it correctly fills the field with the selected value of the list box. My question is when I retrieve that data how do I get the list box to be set on the value of the field?
If the person has previously volunteered for coach when the information comes back I want the select list to show 'coach' not the default.
Sorry if I don't make sense I really appreciate the help.
here is the code: - <tr>
-
<td colspan="5"><div align="center"><strong>PLEASE REVIEW AND UPDATE YOUR INFORMATION</strong></div></td>
-
</tr>
-
<tr>
-
<td width="113"><div align="right">Street - City - Zip:</div></td>
-
<td width="212"><input name="xaddr" type="text" value="<?php echo $address;?>" id="xaddr" size="35" maxlength="35"></td>
-
<td width="90"><input name="xcity" type="text" value="<?php echo $city;?>" id="xcity" size="15" maxlength="15"> </td>
-
<td width="81"><input name="xzip" type="text" value="<?php echo $zip;?>" id="xzip" size="5" maxlength="5"></td>
-
<td width="69"> </td>
-
</tr>
-
<tr>
-
<td><div align="right">Parents/Guardians:</div></td>
-
<td><input name="xp1first" type="text" value="<?php echo $mfirst;?>" id="xp1first" size="15" maxlength="15">
-
<input name="xp1last" type="text" value="<?php echo $mlast;?>" id="xp1last" size="15" maxlength="15"></td>
-
<td colspan="3"><input name="xp2first" type="text" value="<?php echo $dfirst;?>" id="xp2first" size="15" maxlength="15">
-
<input name="xp2last" type="text" value="<?php echo $dlast;?>" id="xp2last" size="15" maxlength="15"></td>
-
</tr>
-
<tr>
-
<td><div align="right">Volunteer For?:</div></td>
-
<td><select name="select" id="select">
-
<option value="Manager">Manager</option>
-
<option value="Coach">Coach</option>
-
<option value="Asst. Coach">Asst Coach</option>
-
<option value="Team Mom">Team Mom</option>
-
<option value="Umpire">Umpire</option>
-
<option value="Scorekeeper">Scorekeeper</option>
-
<option value="Snack Bar">Snack Bar</option>
-
<option value="League Official">League Official</option>
-
<option value="Field Maintenance">Field Maintenance</option>
-
<option value="Team Photographer">Team Photographer</option>
-
<option value="Team Computer Rep">Team Computer Rep</option>
-
<option value="Other">Other</option>
-
<option value="None" selected>No thanks</option>
-
</select></td>
-
<td colspan="2"><select name="select2" id="select2">
-
<option value="Manager">Manager</option>
-
<option value="Coach">Coach</option>
-
<option value="Asst. Coach">Asst Coach</option>
-
<option value="Team Mom">Team Mom</option>
-
<option value="Umpire">Umpire</option>
-
<option value="Scorekeeper">Scorekeeper</option>
-
<option value="Snack Bar">Snack Bar</option>
-
<option value="League Official">League Official</option>
-
<option value="Field Maintenance">Field Maintenance</option>
-
<option value="Team Photographer">Team Photographer</option>
-
<option value="Team Computer Rep">Team Computer Rep</option>
-
<option value="Other">Other</option>
-
<option value="None" selected>No thanks</option>
-
</select></td>
-
<td> </td>
-
</tr>
-
<tr>
-
<td><div align="right">Email 1:</div></td>
-
<td><input name="xemail" type="text" value="<?php echo $email;?>" id="xemail" size="30" maxlength="40"></td>
-
<td colspan="2"><input name="xemail3" type="text" value="<?php echo $email3;?>" id="xemail3" size="30" maxlength="40"></td>
-
<td> </td>
-
</tr>
-
<tr>
-
<td><div align="right">Email 2:</div></td>
-
<td><input name="xemail2" type="text" value="<?php echo $email2;?>" id="xemail2" size="30" maxlength="40"></td>
-
<td colspan="2"><input name="xemail4" type="text" value="<?php echo $email4;?>" id="xemail4" size="30" maxlength="40"></td>
-
<td> </td>
-
</tr>
-
<tr>
-
<td><div align="right">Phones (10digits):</div></td>
-
<td><div align="left">
-
<input name="xhphone" type="text" id="xhphone" value="<?php echo $phone;?>" size="10" maxlength="10">
-
<input name="xphone2" type="text" id="xphone2" value="<?php echo $cphone2;?>" size="10" maxlength="10">
-
</div></td>
-
<td colspan="2"><input name="xphone3" type="text" value="<?php echo $cphone3;?>" id="xphone3" size="10" maxlength="10">
-
<input name="xphone" type="text" value="<?php echo $cphone4;?>" id="xphone" size="10" maxlength="10"></td>
-
<td> </td>
-
</tr>
-
<tr>
-
<td><div align="right">Second Address:</div></td>
-
<td><input name="xaddr2" type="text" value="<?php echo $address2;?>" id="xaddr2" size="35" maxlength="35"></td>
-
<td><input name="xcity2" type="text" value="<?php echo $city2;?>" id="xcity2" size="15" maxlength="15"></td>
-
<td><input name="xzip2" type="text" value="<?php echo $zip2;?>" id="xzip2" size="5" maxlength="5"></td>
-
<td> </td>
-
</tr>
In that case, I would output the <option>s via a loop, checking each against the result from the database. -
$volunteer_options = array(
-
'Manager' => 'Manager',
-
'Coach' => 'Coach',
-
'Asst' => 'Assistant',
-
....
-
);
-
-
// This value you will have to pull from the database
-
// I will hardcode it here.
-
$volunteer_choice = 'Asst';
-
-
print '<select name="volunteer">';
-
foreach ($volunteer_options as $key => $option) {
-
printf('<option name="%s" %s>%s</option>',
-
$key,
-
($key == $volunteer_choice) ? 'selected="selected"' : '',
-
$option
-
);
-
}
-
print '</select>';
-
Is that what you're after?
Mark.
Thanks Mark, looking at the code I think that could be the answer. I will give it a try in the morning, your evening (your time stamp appears to be 8 hrs ahead). Thanks again.
Mark,
Your code should create exactly what I am looking for. Unfortunately, I am struggling to make it work. I know it is something I am doing wrong. I researched printf and associative arrays on w3schools.com but I am still failing.
When you have a minute could you look at it.
This is the output I get (notice the first key and assignment operator are not output). The code I am using follows the display.
'Manager', 'Coach' => 'Coach', 'Asst Coach' => 'Asst Coach', 'Team Mom' => 'Team Mom', 'Umpire' => 'Umpire', 'Scorekeeper' => 'Scorekeeper', 'Snack Bar' => 'Snack Bar', 'League Official' => 'League Official', 'Field Maintenance' => 'Field Maintenance', 'Team Photographer' => 'Team Photographer', 'Team Computer Rep' => 'Team Computer Rep', 'Other' => 'Other', 'None' => 'No Thanks' ); // This value you will have to pull from the database // I will hardcode it here. $volunteer_choice = 'Asst Coach'; print ''; ?>
select.php - <html>
-
<body>
-
<?php
-
-
$volunteer_options=array(
-
'Manager' => 'Manager',
-
'Coach' => 'Coach',
-
'Asst Coach' => 'Asst Coach',
-
'Team Mom' => 'Team Mom',
-
'Umpire' => 'Umpire',
-
'Scorekeeper' => 'Scorekeeper',
-
'Snack Bar' => 'Snack Bar',
-
'League Official' => 'League Official',
-
'Field Maintenance' => 'Field Maintenance',
-
'Team Photographer' => 'Team Photographer',
-
'Team Computer Rep' => 'Team Computer Rep',
-
'Other' => 'Other',
-
'None' => 'No Thanks'
-
);
-
-
// This value you will have to pull from the database
-
// I will hardcode it here.
-
$volunteer_choice = 'Asst Coach';
-
-
print '<select name="volunteer">';
-
foreach ($volunteer_options as $key => $option) {
-
printf('<option name="%s" %s>%s</option>',
-
$key,
-
($key == $volunteer_choice) ? 'selected="selected"' : '',
-
$option
-
);
-
}
-
print '</select>';
-
-
?>
-
</body></html>
Hey, Dave.
The problem is the PHP isn't being parsed. Are you saving this file as .php and running it under your server? That is, accessing it as http://localhost/file.php.
Mark.
P.S. Check out the Please Read Before Posting sticky - specifically, the part about [code] tags. Cheers.
Mark,
Ouch. I told you I didn't know much. Once I moved the file to htdocs everything worked perfect. I cannot thank you enough for being so willing to share your knowledge.
Newbie's rarely contribute, but I did my part. I provided comedy for the day. Anyone following this thread will laugh at the bleeping idiot.
Thanks again.
@CoachDave48
I assure you we've all be there :) and no one's laughing at you! :P
Anyway, be sure to come back with any questions you have.
Mark.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nick Truscott |
last post by:
Is this possible?
I have a form which asks the user to input the result of a soccer
match.
I want to then use a choice of three sets of queries (Home Win, Away
Win, Draw) to update two...
|
by: cooldv |
last post by:
i am running a website on Windows 2000 server with ASP 3 webpages and
Access 2000 database. (with a hosting company)
traffic is slow at this time but expect to grow. lately i have been
reading...
|
by: baustin75 |
last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie
only when debugging in php designer 2005
--------------------------------------------------------------------------------
...
|
by: deercreek |
last post by:
I could use a little help from a good code writer out there. I found
some code and modified it a bit for my needs but, I need a little help
to finish it up. What I am trying to due is to get a...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted...
|
by: sandeepsandeep |
last post by:
Hellow
i am facing a problem in mysql query plesae solve it.
I have a table Team_master with two field
1. team_id
2. team_name
|
by: dm06tw |
last post by:
Hi there,
I've got a question about an odd annoyance that's been happening on our new php form. The form originally had javascript controlled dynamic dropdown boxes which would force the user to...
|
by: Atli |
last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t.
In situations where your PHP application...
|
by: dmstn |
last post by:
Hey! I've got a little problem. I have to make a web site for a university essay. I curently have to create a search engine. Users can enter a hotel name in a search bar and results have to appear in...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |