Jump to content

Form and Error Checking


Daney11

Recommended Posts

Hey guys.

 

I have this peice of code below which creates numbers from 1-99 for each record in my form.

Example:

Num    Name

1        Dane

2        Milk

3        Shake

4        Pig

 

<select name='squad_number[<?php $i; ?>]' class="input">

<?php

for ($a=1; $a<=99; $a++) { if($a<10) { $val="$a"; } else { $val=$a; } 

echo "<option value='$val'"; 

if ($val==$Squad_PlayerRow['squad_number']) { 

echo " selected"; } 

echo ">$val</option>";

}

?>
</select>

 

Once submitted, it updates the database setting the relevant fields to the number selected from the form above.

However i need to add error checking to it. If, for example:

Example:

Num    Name

1        Dane

2        Milk

1        Shake

4        Pig

 

You will see "Dane" and "Shake" each have the number "1", and i want that to return an error saying that you can not use the same number twice basically. Im using:

 

if (eregi ('^[[:digit:]]{1,2}$', stripslashes(trim($_POST['squad_number'][$i])))) {
$squad_number = $_POST['squad_number'][$i];
} else {
   $squad_number = FALSE;
   $errors[] = 'Please enter a correct team number.';
       }

 

To check if that value in the select menu is actually a number between 1-99, and this works fine. How would i create a error checking to find wether a number has been used twice.

 

Thanks

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.