Jump to content

checking entire array has no empty/null fields


rvinikof

Recommended Posts

Using this code:

 

if ($Numofbooks != "")

							{
								for ($i = 0; $i < $Numofbooks; $i++)
								{
								$Author = $_POST["bookauthor"];
								$Title = $_POST["booktitle"];
								$Edition = $_POST["edition"];
								$ISBN = $_POST["isbn"];
								$ReqorOpt = $_POST["reqoropt"];


								if (isset($Author[$i]))
									{ echo "<center>";
									  echo "Please enter an author for every book.";
									  echo '<br/><a><input type="button" value = "Back." onclick = "history.go(-1)"></a>';
									  echo "</center>";
									  exit(); }

								if ($Title[$i] == "")
									{ echo "<center>";
									  echo "Please enter a title for every book.";
									  echo '<br/><a><input type="button" value = "Back." onclick = "history.go(-1)"></a>';
									  echo "</center>";
									  exit(); }

								if (($ISBN[$i] == "") || (strlen($ISBN[$i]) != 13))
									{ echo "<center>";
									  echo "Please enter a 13-digit ISBN for every book.";
									  echo '<br/><a><input type="button" value = "Back." onclick = "history.go(-1)"></a>';
									  echo "</center>";
									  exit(); } 

								$sqlinsertlogin = "INSERT INTO bookrequest (requestID, author, title, edition, isbn, loginID, reqoropt, 

courseID) VALUES ('', '".$Author[$i]."', '".$Title[$i]."', '".$Edition[$i]."', '".$ISBN[$i]."', '".$loginid[0]."', '".$ReqorOpt[$i]."', '".$crnforclass[0]."')";
								$insertlogin = mysql_query($sqlinsertlogin);
									if (!$insertlogin)
										{ $insertloginerr = mysql_error();
					 			  		  echo $insertloginerr;
					  			  		  exit(); }


								}		


							}

 

I'm trying to check to make sure that for every book, every author, title, and isbn is not empty. However, it seems like it only checks the first book. If the first book has an author, but the second doesn't, then it checks title and keeps going. The only time the error pops up is if the first author, title, isbn is empty. How do I make sure that it checks for every author?

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.