473,320 Members | 1,862 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,320 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 2471
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.