I need some help. I'm trying to tweak a code and keep hitting my head against a wall. It's for a game that I am running where a user has "horses" that they enter into "classes" which are a part of "shows." They can have multiple horses and no limits, however the horse has to meet certain requirements in order to enter the classes. At the class page, a user sees their eligible horses in a drop down select list, they hit submit, and the horse is entered. They have to do this multiple times for each of their horses. However, I am trying to make it so that they can either a) see a submit all eligible horses button, which would insert all of the eligible horses with one click or b) see their list of eligible horses as checkboxes where they can select which ones they want and submit and have the horses inserted. I really don't care which it is, if it's easier to do the submit all that's fine. I was trying to get the checkbox portion to work, but I haven't had any luck. Any help would be much appreciated. Here is the code:
Expand|Select|Wrap|Line Numbers
- <?php
- session_start(); // Maintain session state
- header("Cache-control: private"); // Fixes IE6's back button problem.
- $page_title = "Class Information";
- include('header.php');
- $class_id = $_GET['id'];
- $enter = $_POST['enter_horse'];
- $check = $_POST['check'];
- $horse_id = $_POST['horse_id'];
- //general show information
- $result = @mysql_query("SELECT s.show_id, s.player_id, s.type, s.name, DATEDIFF(s.run_date, NOW()) AS datedif, c.class_id, s.entry_fee FROM classes c, shows s WHERE c.class_id='$class_id' AND c.show_id=s.show_id LIMIT 1")or die("Cannot find class! " . mysql_error());
- $row = @mysql_fetch_array($result);
- $show_id = $row['show_id'];
- $show_name = $row['name'];
- $runs_in = $row['datedif'];
- $species = $row['species'];
- $type = $row['type'];
- $owner_id = $row['player_id'];
- if(!$row['class_id']){myError("Invalid class!");include('footer.php');}
- $entry_fee = $row['entry_fee'];
- $num_entries = @mysql_num_rows(@mysql_query("SELECT horse_id FROM horses_entered WHERE class_id='$class_id'"));
- $runs_in = "$runs_in day[s]";
- if($enter){
- //ensure horse is eligible to enter
- $good = @mysql_num_rows(@mysql_query("SELECT horse_id FROM horses WHERE horse_id='$horse_id' AND player_id='$player_id' AND age>=2 AND age<=20"));
- $exists = @mysql_num_rows(@mysql_query("SELECT horse_id FROM horses_entered WHERE horse_id='$horse_id' AND class_id='$class_id' LIMIT 1"));
- if($my_money < $entry_fee){myError("You cannot afford the entry fee.", 1);}
- if(!$good){myError("Are you sure you own the horse and it is between 3 and 20 years of age?");
- }elseif($exists){myError("That horse is already entered in this class!");
- }else{
- @mysql_query("INSERT INTO horses_entered(horse_id, class_id) VALUES('$horse_id', '$class_id')")or die("Cannot create entry!");
- if($type == 1 AND $entry_fee){@mysql_query("UPDATE players SET money=money+'$entry_fee' WHERE player_id='$owner_id' LIMIT 1")or die("Cannot update player money!"); $points=1;
- }elseif($type == 2 AND $entry_fee){@mysql_query("UPDATE clubs SET money=money+'$entry_fee' WHERE president='$owner_id' LIMIT 1")or die("Cannot update player money2!"); $points=2;}
- @mysql_query("UPDATE players SET money=money-'$entry_fee', points=points+'$points' WHERE player_id='$player_id' LIMIT 1")or die("Cannot update player money3! " . @mysql_error());
- @mysql_query("UPDATE horses SET points=points+1 WHERE horse_id='$horse_id' LIMIT 1")or die("Cannot update horse points!");
- myError("Class entered!");
- }
- }
- //display the show information
- echo "<table>
- <tr><td><b>Class:</td><td>#$class_id</td></tr>
- <tr><td><b>Show:</td><td><a href='shows.php?id=$show_id'>$show_name (#$show_id)</a></td></tr>
- <tr><td><b>Runs:</td><td>$runs_in</td></tr>
- <tr><td><b>Entry Fee:</td><td>$$entry_fee</td></tr>
- <tr><td><b>Total Entrants:</td><td>$num_entries</td></tr>
- <tr><td valign=top><b>Your Horses:</td><td>
- <form action='classes.php?id=$class_id' method=POST>
- <select name='horse_id'>
- ";
- $result = @mysql_query("SELECT horse_name, breed, horse_id FROM horses WHERE player_id='$player_id' AND age>2 AND age<=20 ORDER BY horse_name ASC")or die("Cannot find horses! " . mysql_error());
- while($row = @mysql_fetch_array($result)):
- $horse_id = $row['horse_id'];
- $horse_name = stripslashes($row['horse_name']);
- $breed = $row['breed'];
- echo "<option value='$horse_id'>$horse_name (#$horse_id), $breed</option>\n";
- $prev_species = $species;
- endwhile;
- if(!$horse_id){echo "<option value=0>No eligible horses!";}
- echo "
- </select>
- <input type=submit name='enter_horse' value='Enter Horse!'></td></tr></form>
- <tr><td valign=top><b>Entrants:</td><td>
- ";
- }
- $query = "SELECT h.horse_name, h.horse_id, h.breed FROM horses_entered he LEFT JOIN horses h ON he.horse_id=h.horse_id WHERE he.class_id='$class_id' ORDER BY h.horse_name ASC";
- $result = @mysql_query($query)or die(mysql_error());
- while($row = @mysql_fetch_array($result)):
- $name = $row['horse_name'];
- $aid = $row['horse_id'];
- $breed = $row['breed'];
- $page = "horses.php";
- echo "<a href='$page?id=$aid'>$name (#$aid)</a>, $breed<br>\n";
- endwhile;
- if(!$aid){echo "<i>No entrants.";}
- echo "</td></tr>
- </table>";
- include('footer.php');
- ?>