Jump to content

Annoying Little Error


Ell20

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:

teamselectionqc9.jpg

 

Rather than this (nice artwork I no, but I think you see my point?):

teamselectionnovz3.jpg

 

Cheers

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.