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
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
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
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
Share on other sites

There is 1 select box per line in the array. Which is squad_number[$i].

 

My code works perfectly without error checking. Im just wanting to find a way to check that in the array of squad_number[$i], a same number hasnt been chosen twice...

Link to comment
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
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.