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?

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.