473,441 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

Help with Mysql database for Little League

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
Oct 27 '09 #1
10 2478
Markus
6,050 Expert 4TB
Run an UPDATE query on your table with the relevant information. I assume you're POSTing the data.

Expand|Select|Wrap|Line Numbers
  1. UPDATE `tbl_name` SET `col_1` = '$col_1' WHERE `userid` = $userid;
  2.  
Obviously you need to set the values of $col_1 and $userid, and also change the tbl_name and col_1 identifiers.
Oct 27 '09 #2
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:
Expand|Select|Wrap|Line Numbers
  1.  <tr>
  2.       <td colspan="5"><div align="center"><strong>PLEASE REVIEW AND UPDATE YOUR INFORMATION</strong></div></td>
  3.     </tr>
  4.     <tr>
  5.       <td width="113"><div align="right">Street - City - Zip:</div></td>
  6.       <td width="212"><input name="xaddr" type="text" value="<?php echo $address;?>"  id="xaddr" size="35" maxlength="35"></td>
  7.       <td width="90"><input name="xcity" type="text"  value="<?php echo $city;?>" id="xcity" size="15" maxlength="15"> </td>
  8.       <td width="81"><input name="xzip" type="text"  value="<?php echo $zip;?>" id="xzip" size="5" maxlength="5"></td>
  9.       <td width="69">&nbsp;</td>
  10.     </tr>
  11.     <tr>
  12.       <td><div align="right">Parents/Guardians:</div></td>
  13.       <td><input name="xp1first" type="text"  value="<?php echo $mfirst;?>" id="xp1first" size="15" maxlength="15">
  14.       <input name="xp1last" type="text"  value="<?php echo $mlast;?>" id="xp1last" size="15" maxlength="15"></td>
  15.       <td colspan="3"><input name="xp2first" type="text" value="<?php echo $dfirst;?>"  id="xp2first" size="15" maxlength="15">
  16.       <input name="xp2last" type="text" value="<?php echo $dlast;?>"  id="xp2last" size="15" maxlength="15"></td>
  17.     </tr>
  18.     <tr>
  19.       <td><div align="right">Volunteer For?:</div></td>
  20.       <td><select name="select" id="select">
  21.         <option value="Manager">Manager</option>
  22.         <option value="Coach">Coach</option>
  23.         <option value="Asst. Coach">Asst Coach</option>
  24.         <option value="Team Mom">Team Mom</option>
  25.         <option value="Umpire">Umpire</option>
  26.         <option value="Scorekeeper">Scorekeeper</option>
  27.         <option value="Snack Bar">Snack Bar</option>
  28.         <option value="League Official">League Official</option>
  29.         <option value="Field Maintenance">Field Maintenance</option>
  30.         <option value="Team Photographer">Team Photographer</option>
  31.         <option value="Team Computer Rep">Team Computer Rep</option>
  32.         <option value="Other">Other</option>
  33.         <option value="None" selected>No thanks</option>
  34.       </select></td>
  35.       <td colspan="2"><select name="select2" id="select2">
  36.         <option value="Manager">Manager</option>
  37.         <option value="Coach">Coach</option>
  38.         <option value="Asst. Coach">Asst Coach</option>
  39.         <option value="Team Mom">Team Mom</option>
  40.         <option value="Umpire">Umpire</option>
  41.         <option value="Scorekeeper">Scorekeeper</option>
  42.         <option value="Snack Bar">Snack Bar</option>
  43.         <option value="League Official">League Official</option>
  44.         <option value="Field Maintenance">Field Maintenance</option>
  45.         <option value="Team Photographer">Team Photographer</option>
  46.         <option value="Team Computer Rep">Team Computer Rep</option>
  47.         <option value="Other">Other</option>
  48.         <option value="None" selected>No thanks</option>
  49.       </select></td>
  50.       <td>&nbsp;</td>
  51.     </tr>
  52.     <tr>
  53.       <td><div align="right">Email 1:</div></td>
  54.       <td><input name="xemail" type="text"  value="<?php echo $email;?>" id="xemail" size="30" maxlength="40"></td>
  55.       <td colspan="2"><input name="xemail3" type="text"  value="<?php echo $email3;?>" id="xemail3" size="30" maxlength="40"></td>
  56.       <td>&nbsp;</td>
  57.     </tr>
  58.     <tr>
  59.       <td><div align="right">Email 2:</div></td>
  60.       <td><input name="xemail2" type="text"  value="<?php echo $email2;?>" id="xemail2" size="30" maxlength="40"></td>
  61.       <td colspan="2"><input name="xemail4" type="text"  value="<?php echo $email4;?>" id="xemail4" size="30" maxlength="40"></td>
  62.       <td>&nbsp;</td>
  63.     </tr>
  64.     <tr>
  65.       <td><div align="right">Phones (10digits):</div></td>
  66.       <td><div align="left">
  67.         <input name="xhphone" type="text" id="xhphone" value="<?php echo $phone;?>" size="10" maxlength="10">
  68.         <input name="xphone2" type="text" id="xphone2"  value="<?php echo $cphone2;?>" size="10" maxlength="10">
  69.       </div></td>
  70.       <td colspan="2"><input name="xphone3" type="text"  value="<?php echo $cphone3;?>" id="xphone3" size="10" maxlength="10">
  71.       <input name="xphone" type="text"  value="<?php echo $cphone4;?>" id="xphone" size="10" maxlength="10"></td>
  72.       <td>&nbsp;</td>
  73.     </tr>
  74.     <tr>
  75.       <td><div align="right">Second Address:</div></td>
  76.       <td><input name="xaddr2" type="text"  value="<?php echo $address2;?>" id="xaddr2" size="35" maxlength="35"></td>
  77.       <td><input name="xcity2" type="text"  value="<?php echo $city2;?>" id="xcity2" size="15" maxlength="15"></td>
  78.       <td><input name="xzip2" type="text"  value="<?php echo $zip2;?>" id="xzip2" size="5" maxlength="5"></td>
  79.       <td>&nbsp;</td>
  80.     </tr>
Oct 27 '09 #3
Markus
6,050 Expert 4TB
In that case, I would output the <option>s via a loop, checking each against the result from the database.

Expand|Select|Wrap|Line Numbers
  1. $volunteer_options = array(
  2.     'Manager' => 'Manager',
  3.     'Coach' => 'Coach',
  4.     'Asst' => 'Assistant',
  5.     ....
  6. );
  7.  
  8. // This value you will have to pull from the database
  9. // I will hardcode it here.
  10. $volunteer_choice = 'Asst';
  11.  
  12. print '<select name="volunteer">';
  13. foreach ($volunteer_options as $key => $option) {
  14.     printf('<option name="%s" %s>%s</option>',
  15.             $key,
  16.             ($key == $volunteer_choice) ? 'selected="selected"' : '',
  17.             $option
  18.     );
  19. }
  20. print '</select>';
  21.  
Is that what you're after?

Mark.
Oct 27 '09 #4
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.
Oct 27 '09 #5
Markus
6,050 Expert 4TB
@CoachDave48
Brill. Let us know how you get on.
Oct 27 '09 #6
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
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  <body>
  3.  <?php 
  4.  
  5.      $volunteer_options=array(
  6.      'Manager' => 'Manager',
  7.      'Coach' => 'Coach',
  8.      'Asst Coach' => 'Asst Coach',
  9.      'Team Mom' => 'Team Mom',
  10.      'Umpire' => 'Umpire',
  11.      'Scorekeeper' => 'Scorekeeper',
  12.      'Snack Bar' => 'Snack Bar',
  13.      'League Official' => 'League Official',
  14.      'Field Maintenance' => 'Field Maintenance',
  15.      'Team Photographer' => 'Team Photographer',
  16.      'Team Computer Rep' => 'Team Computer Rep',
  17.      'Other' => 'Other',
  18.      'None' => 'No Thanks'
  19.       );
  20.  
  21.  // This value you will have to pull from the database
  22.  // I will hardcode it here.
  23.  $volunteer_choice = 'Asst Coach';
  24.  
  25.  print '<select name="volunteer">';
  26.  foreach ($volunteer_options as $key => $option) {
  27.      printf('<option name="%s" %s>%s</option>',
  28.              $key,
  29.              ($key == $volunteer_choice) ? 'selected="selected"' : '',
  30.              $option
  31.      );
  32.  }
  33.  print '</select>';
  34.  
  35.  ?>
  36.  </body></html>
Oct 28 '09 #7
Markus
6,050 Expert 4TB
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.
Oct 28 '09 #8
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.
Oct 29 '09 #9
Markus
6,050 Expert 4TB
@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.
Oct 29 '09 #10
Dormilich
8,658 Expert Mod 8TB
@CoachDave48
I can assure you that we've seen worse.
Oct 29 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
3
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...
8
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 -------------------------------------------------------------------------------- ...
5
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...
0
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...
2
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
2
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...
221
Atli
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...
2
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
1
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...
0
tracyyun
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...
0
agi2029
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.