Ell20 Posted November 3, 2007 Share Posted November 3, 2007 Hey guys, Ive created a team selection page for a sports club. When you add a player to the team selection I have created selection boxes to ask whether the player selected is: Captain, Vice-Captain Or Wicketkeeper. However when I display my results on the form I dont want No,No written over the page if they are not Captain etc, I just want a blank space. This however is causing problems when the information is being stored in the database because the variable does not exist if the value is not selected e.g they are not captain etc. How can I get around this problem? Cheers Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted November 3, 2007 Share Posted November 3, 2007 about the variable: <?php if(isset($var)){ // Do this } ?> Didn't really understand the rest. Any code to show? Quote Link to comment Share on other sites More sharing options...
Ell20 Posted November 3, 2007 Author Share Posted November 3, 2007 This is the part of the form where they select whether the player is any of the following: <tr> <td> Captain: </td> <td> <input type="checkbox" name="captain" value="Yes" /> </td> </tr> <tr> <td> Vice Captain: </td> <td> <input type="checkbox" name="vicecaptain" value="Yes" /> </td> </tr> <tr> <td> Wicketkeeper: </td> <td> <input type="checkbox" name="wicketkeeper" value="Yes" /> </td> </tr> This is the code to insert the results into the database: <?php if (isset($_POST['submit2'])) { $captain = escape_data($_POST['captain']); $vice_captain = escape_data($_POST['vicecaptain']); $wicketkeeper = escape_data($_POST['wicketkeeper']); $name = $_POST['fixturedrp3']; $fixture_id = $_POST['fixturedrp2']; /* If other is selected from drop down box take value from text box */ if($_POST['fixturedrp3'] == 'Other') { $name = $_POST['textboxother']; } /* If other is selected from drop down box and no value put into text box display error */ if($name == "") { echo '<h3>If you select Other, you must type in a player name</h3>'; include ('includes/footer.html'); exit(); } $query = "INSERT INTO team_selection (club_id, fixture_id, player_name, captain, vice_captain, wicket_keeper) VALUES ('$id', '$fixture_id', '$name', '$captain', '$vice_captain', '$wicketkeeper')"; $result = @mysql_query ($query); if ($result) { echo '<h3>Player Added To Team Selection!</h3>'; } } }}}}} ?> As I was saying if the player is not captain etc it gives the following error: An error occured in script c:\program files\easyphp1-8\www\html\teamselection.php on line 238: Undefined index: captain Cheers Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted November 3, 2007 Share Posted November 3, 2007 Could you indicate which line that is? Quote Link to comment Share on other sites More sharing options...
Ell20 Posted November 3, 2007 Author Share Posted November 3, 2007 Sorry, Line 238 is: $captain = escape_data($_POST['captain']); Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted November 3, 2007 Share Posted November 3, 2007 I'm guessing captain hasn't been set. In which case, check your form validation code, and make sure there has to be a value to escape. Quote Link to comment Share on other sites More sharing options...
Ell20 Posted November 3, 2007 Author Share Posted November 3, 2007 Thats exactly my point. I dont always want it to be set. Not every player can be the captain of the team. I can solve the problem by adding the alternative selection box "No" however I am trying to avoid having No written all over my table. Id like it to look like this: Rather than this (nice artwork I no, but I think you see my point?): Cheers Quote Link to comment Share on other sites More sharing options...
Ell20 Posted November 3, 2007 Author Share Posted November 3, 2007 Anyone got any ideas? Cheers Quote Link to comment Share on other sites More sharing options...
Ell20 Posted November 3, 2007 Author Share Posted November 3, 2007 I guess there is no way in which to enter nothing or NULL into the database so that when data is retrieve the space will be blank? Thanks for any help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.