Jump to content

Code Help


Ell20

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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']) : '';

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.