Jump to content

Error Checking


Daney11

Recommended Posts

Hey guys.

 

I have a form and when it is submitted it gives each user a number from a drop down menu. However two users are not allowed the same number so im using

 

<?php

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

?>

 

However im getting the error. "Please enter a correct team number." Even though each number is different.

Link to comment
https://forums.phpfreaks.com/topic/149906-error-checking/
Share on other sites

Hmm.

 

How would i structure this then?

 

I want it so that two numbers can not equal each other in the array.

 

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

<?php

for ($a=0; $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>

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/149906-error-checking/#findComment-787274
Share on other sites

Ive got with this aswell

 

if ($_POST['squad_number'][$i] == $_POST['squad_number'][$i]) {
  	$squad_number = FALSE;
$errors[] = 'Two players can not have the same number.';
} else {
  	$squad_number = $_POST['squad_number'][$i];
   }

 

But it throws up the two players can not error.

Link to comment
https://forums.phpfreaks.com/topic/149906-error-checking/#findComment-787288
Share on other sites

Basically i have a form with numbers from 0-99. Which is below.

 

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

<?php

for ($a=0; $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>

 

And when i click submit it goes to update.php and updates fine without any error checking. However if there are two numbers that are the same in value squad_number[$i] then i want error checking to say that you cannot choose the same number twice.

 

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.';
       }


if ($_POST['squad_number'][$i] == $_POST['squad_number'][$i]) {
    $squad_number = FALSE;
    $errors[] = 'Two players can not have the same number.';
} else {
    $squad_number = $_POST['squad_number'][$i];
   }

Link to comment
https://forums.phpfreaks.com/topic/149906-error-checking/#findComment-787295
Share on other sites

The following line is missing an echo:

 

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

 

should be:

 

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

 

So you are having multiple select boxes? Where does it get $i from? Can you show the full code?

Link to comment
https://forums.phpfreaks.com/topic/149906-error-checking/#findComment-787307
Share on other sites

If the user.. i.e. Myself, has chosen the same number twice from:

 

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

<?php

for ($a=0; $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>

 

Num:        Name:

1            Dane

2            Milk

3            Cow

1            Pig

 

^^ Number 1 has been chosen twice, so its wrong.

 

Num:        Name:

1            Dane

2            Milk

3            Cow

4            Pig

 

^^ This would return fine.

Link to comment
https://forums.phpfreaks.com/topic/149906-error-checking/#findComment-787578
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.