Jump to content

Recommended Posts

would it have been better to use case over if in this snippet of my script.

<?php// Below checks to see if anything was forgotten!!!!  //
if ($q1 == "") {
  die ("You forgot something, go back and check over your quiz.");
}
if ($q2 == "") {
  die ("You forgot something, go back and check over your quiz.");
}
if ($q3 == "") {
  die ("You forgot something, go back and check over your quiz.");
}
if ($q4 == "") {
  die ("You forgot something, go back and check over your quiz.");
}
if ($q5 == "") {
  die ("You forgot something, go back and check over your quiz.");
}if ($q6 == "") {
  die ("You forgot something, go back and check over your quiz.");
}
if ($q7 == "") {
  die ("You forgot something, go back and check over your quiz.");
}
if ($q8 == "") {
  die ("You forgot something, go back and check over your quiz.");
}
if ($q9 == "") {
  die ("You forgot something, go back and check over your quiz.");
}
if ($q10 == "") {
  die ("You forgot something, go back and check over your quiz.");
}
// Below is where the answers are checked actually displayed //?>

Link to comment
https://forums.phpfreaks.com/topic/106987-solved-quick-question/
Share on other sites

If it's the same die statement, just use 1 if:

<?php// Below checks to see if anything was forgotten!!!!  //
if (empty($q1) || empty($q2) || empty($q3) || empty($q4) || empty($q5) || empty($q6) || empty($q7) || empty($q8) || empty($q9) || empty($q10)) {
  die ("You forgot something, go back and check over your quiz.");
}
// Below is where the answers are checked actually displayed //?>

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.