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
https://forums.phpfreaks.com/topic/150072-form-and-error-checking/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.