I have a whole load of code that basically sorts through the data received from a user input form and based on 4 clauses does one of 4 things. The first three are echo an error message, the last being insert data into the mysql database.......
Here's the thing, if there are 3 rows that match the first error message clause, it echos the error message 3 times, which I don't want. How do I make it only echo it once?
I was thinking mysql_num_rows, but cannot make it work.
Here is the code I have so far. When I run the code I get the error message mysql_num_rows(): supplied argument is not a valid MySQL result resource for the lines where the data from the forms matches the if / else if clauses on the lines where it has if ($Count_Check >0)
Can anyone make any suggestions on how I get this to work - thanks
if (is_array($_POST['Size']) && count($_POST['Size'])>0)
{
$arr_size = count($_POST['Size']);
for ($i=0; $i< $arr_size; $i++)
{
// if the user has put the size in but not thecode
if (!empty($_POST['Size'][$i]) && empty($_POST['Id'][$i]))
{ $count_check = mysql_num_rows($i);
if ($count_check > 0)
{
echo "<br><br><br><br>" .
"<font face=\"Arial, Helvetica, sans-serif\">" .
"Sorry, it appears that a <b>Code</b> is missing.<br>" .
" Please kindly return to the " .
"input form, and re-enter this code. " .
"<br>Thank you" .
"</font>";
}
}
// if the user has put neither the size in nor the code
else if (empty($_POST['Size'][$i]) && empty($_POST['Id'][$i]))
{ $count_check = mysql_num_rows($i);
if ($count_check > 0)
{
echo"<br><br><br><br><font face=\"Arial, Helvetica, sans-serif\">" .
"You have chosen not to enter data today " .
"<br>Please ensure that you log back in when " .
" you have the remaining information" .
"<br>Thank you</font>" ;
}
}
// if the user has put the code in but not the data
else if (empty($_POST['Size'][$i]) && !empty($_POST['Id'][$i]))
{ $count_check = mysql_num_rows($i);
if ($count_check > 0)
{
echo "<br><br><br><br><font face=\"Arial, Helvetica, sans-serif\">" .
"Sorry, it appears that the information " .
"are missing.<br><br>Please click on the back " .
" arrow of your browser to return to the " .
"input form, and re-enter this code. <br>Thank you</font>";
}
}
// insert the record
else
{
$SectionRef = $_POST['SectionRef'];
// sets date into correct format to match database
$today = date('YmdHis');
$Size = strip_tags(trim($_POST['Size'][$i]));
$Colour = strip_tags(trim($_POST['Colour'][$i]));
$Id = ($_POST['Id'][$i]);
$query = "INSERT INTO tblResults (DateRef,MRef,SRef,CRef,Size,Colour,LoadedBy)
VALUES ('$DateRef','$Id','$SRef','$CRef','$Size','$Colour','$UserId')";
$result = mysql_query($query)
or die(mysql_error());
}
} // close for i < $arr_size
} //close if count > 0