I have a user input form whereby not all of the rows will be completed at the same time.
I want an error message to say 'you have chosen not to input all your information today, please come back another time and do it ' or something like that...
For example, the user will see 3 rows of information they have to fill in, if they only fill in one row today I want to just print the error message once, but the code I have is printing the message once for every row in the form - not brilliant !
I have tried exit() but whilst that makes the message print only the once it also stops the rest of the code (an INSERT query) from functioning......
does anyone have any idea how I can get round this - thanks
the code I have at the moment is
session_start ();
require_once ('../mysql_connect.php');
if (is_array($_POST['BC']) && count($_POST['BC'])>0)
{
$arr_size = count($_POST['BC']);
for ($i=0; $i< $arr_size; $i++)
{
// if the user has put the reading in but not the security code
if (!empty($_POST['BC'][$i]) && empty($_POST['M'][$i]))
{ $count_check = sizeof($i);
if ($count_check > 0)
{
echo "Sorry, it appears that a <b>Code</b> for one of your records" .
"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['BC'][$i]) && empty($_POST['M'][$i]))
{ $count_check = sizeof($i);
if ($count_check > 0)
{
echo"
"You have chosen not to enter information for all your records today " .
"<br>Please ensure that you log back in when you have the remaining info" . "
Thank you $username, <br> <br> your other information has been added<br> and will be processed accordingly." ;
exit(); // this if left in make the error print only once, but stops the insert
// if taken out the INSERT works ok but I get an error message for every record in the form
}
}
// if the user has put the code in but not the info
else if (empty($_POST['BC'][$i]) && !empty($_POST['M'][$i]))
{ $count_check = sizeof($i);
if ($count_check > 0)
{
echo "Sorry, it appears that the <b>Records</b> " .
"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
{
$SRef = $_POST['SRef'];
// sets date into correct format to match database
$today = date('YmdHis');
// establish variable concesref for use in next query
$query = "SELECT `CRef` FROM `tblS` WHERE `SId` = '$SRef'";
$result = mysql_query($query)
or die(mysql_error());
$row = mysql_fetch_array($result);
$CRef = $row["CRef"];
// sets datelogref variable
$query = "SELECT `DateId` FROM `tblDate` WHERE `CRef` = '$CRef' AND `Open` <= '$today'
ORDER BY `EndDate` DESC LIMIT 1";
$result1 = mysql_query($query)
or die(mysql_error());
$row1 = mysql_fetch_array($result1);
$DateRef = $row1["DateId"];
// sets userid
$query = "SELECT WebUserId FROM tblUser WHERE CLogIn ='$username'";
$result5 = mysql_query($query)
or die(mysql_error());
$row5 = mysql_fetch_array($result5);
$UserId = $row5["WebUserId"];
//set client ref
$query = "SELECT `ClientRef` FROM `tblSection` WHERE `SectionId` = '$SectionRef'";
$result4 = mysql_query($query)
or die(mysql_error());
$row4 = mysql_fetch_array($result4);
$ClientRef = $row4["ClientRef"];
$BC = strip_tags(trim($_POST['BC'][$i]));
$CC = strip_tags(trim($_POST['CC'][$i]));
$M = ($_POST['M'][$i]);
$query = "INSERT INTO tblResults (DateRef,MRef,SRef,ClientRef,CRef,BC,CC,LoadedBy)
VALUES ('$DateRef','$M','$SRef','$ClientRef','$CRef','$BC','$CC','$UserId')";
$result = mysql_query($query)
or die(mysql_error());
}
} // close for i < $arr_size
} //close if count > 0
echo "Thank you $username, <br> <br> your information has been added<br> and will be processed accordingly.";