Ell20 Posted November 9, 2007 Share Posted November 9, 2007 Hi, Im creating a sports website where team selection can be added to the fixture. In my team selection table I have the options: Captain, Vice-Captain and Wicketkeeper. They are 3 seperate tick boxes. If all 3 of these tick boxes are selected then the code works perfectly, this however is unreleastic. If any of the selection boxes are not ticked I recieve the following errors: An error occured in script c:\program files\easyphp1-8\www\html\teamselection.php on line 246: Undefined index: captainAn error occured in script c:\program files\easyphp1-8\www\html\teamselection.php on line 247: Undefined index: captainAn error occured in script c:\program files\easyphp1-8\www\html\teamselection.php on line 250: Undefined index: vicecaptainAn error occured in script c:\program files\easyphp1-8\www\html\teamselection.php on line 251: Undefined index: vicecaptainAn error occured in script c:\program files\easyphp1-8\www\html\teamselection.php on line 254: Undefined index: wicketkeeperAn error occured in script c:\program files\easyphp1-8\www\html\teamselection.php on line 255: Undefined index: wicketkeeper The easy soultion to this problem would be to add 2 tick boxes for each of the catergories so that the user either selections Yes Or No. However this is not how I want to do it as I want the user to do as little as possible. Also by having a Yes/No tickbox option the value "No" will be placed all over the team selection table whereas I would just like the table to display the value Yes where it is true and leave it blank where it would normally say "No". Can anyone offer a suggestion as to how I would go about doing this? Thanks Elliot Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted November 9, 2007 Share Posted November 9, 2007 We'll need to see your code. I have a feeling it's a simple matter of form validation, but it's hard suggesting a remedy without seeing how and why the problem occurs. Quote Link to comment Share on other sites More sharing options...
Ell20 Posted November 9, 2007 Author Share Posted November 9, 2007 The html selection boxes in the form: <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> <?php if (isset($_POST['submit2'])) { $captain = escape_data($_POST['captain']); $vice_captain = escape_data($_POST['vicecaptain']); $wicketkeeper = escape_data($_POST['wicketkeeper']); ------etc---------- $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>'; ?> The reason I think it dosent work is because the variable is not defined if the selection box is not ticked? However I dont have a solution to get around this problem? Cheers Quote Link to comment Share on other sites More sharing options...
atlanta Posted November 9, 2007 Share Posted November 9, 2007 is that the right file you showed us because it doesnt look like 200+ lines of codes ... ?? Quote Link to comment Share on other sites More sharing options...
Ell20 Posted November 9, 2007 Author Share Posted November 9, 2007 Thats because I cut out the bits that are neccessary with this problem. The rest of the code is all working fine and is linked to other parts of the page which dont concern the error. Thanks Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted November 9, 2007 Share Posted November 9, 2007 Just like I thought -- form issues. Question: do you only want one of these values (captain, vice captain, wicketkeeper) to be selected? Or should someone be able to select two or more of the options? Quote Link to comment Share on other sites More sharing options...
Ell20 Posted November 9, 2007 Author Share Posted November 9, 2007 The following scenarios could occur: Never will all 3 options be selected as it is impossible to be both captain and vice - captain. Any combiniation of 2 of the boxes can be selected other than captain and vice captain selected. Any single selection box can be selected. All selection boxes can be blank Cheers Quote Link to comment Share on other sites More sharing options...
sasa Posted November 9, 2007 Share Posted November 9, 2007 change $captain = escape_data($_POST['captain']); $vice_captain = escape_data($_POST['vicecaptain']); $wicketkeeper = escape_data($_POST['wicketkeeper']); to $captain = isset($_POST['captain']) ? escape_data($_POST['captain']) : ''; $vice_captain = isset($_POST['vicecaptain']) ? escape_data($_POST['vicecaptain']) : ''; $wicketkeeper = isset($_POST['wicketkeeper']) ? escape_data($_POST['wicketkeeper']) : ''; 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.