Connecting Tech Pros Worldwide Help | Site Map

Help with Mysql database for Little League

Newbie
 
Join Date: Oct 2009
Location: Huntington Beach, California
Posts: 5
#1: 3 Weeks Ago
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
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: 3 Weeks Ago

re: Help with Mysql database for Little League


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.
Newbie
 
Join Date: Oct 2009
Location: Huntington Beach, California
Posts: 5
#3: 3 Weeks Ago

re: Help with Mysql database for Little League


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>
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#4: 3 Weeks Ago

re: Help with Mysql database for Little League


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.
Newbie
 
Join Date: Oct 2009
Location: Huntington Beach, California
Posts: 5
#5: 3 Weeks Ago

re: Help with Mysql database for Little League


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.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#6: 3 Weeks Ago

re: Help with Mysql database for Little League


Quote:

Originally Posted by CoachDave48 View Post

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.

Brill. Let us know how you get on.
Newbie
 
Join Date: Oct 2009
Location: Huntington Beach, California
Posts: 5
#7: 3 Weeks Ago

re: Help with Mysql database for Little League


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.

Quote:
'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>
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#8: 3 Weeks Ago

re: Help with Mysql database for Little League


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.
Newbie
 
Join Date: Oct 2009
Location: Huntington Beach, California
Posts: 5
#9: 3 Weeks Ago

re: Help with Mysql database for Little League


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.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#10: 3 Weeks Ago

re: Help with Mysql database for Little League


Quote:

Originally Posted by CoachDave48 View Post

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.

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.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,620
#11: 3 Weeks Ago

re: Help with Mysql database for Little League


Quote:

Originally Posted by CoachDave48 View Post

Anyone following this thread will laugh at the bleeping idiot.

I can assure you that we've seen worse.
Reply

Tags
form, list select, mysql, php