Jump to content

php if elseif else


facarroll

Recommended Posts

I have a data form which sends to a mysql database.

In the database I have 6 fields which are informed by check boxes and that dataevaluates to true("1") or false("0").

I am trying to write a short script to check whether one or more boxes were checked. I am new at this, but what I've written works well. The problem I have is that I don't know how to insert the script so that it allows the original script to continue if one of or more of the fields evaluates as true.

This is what I have. There is something wrong at the end, I think.

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/207818-php-if-elseif-else/
Share on other sites

Sorry Mr Adam, don't understand. I'll post my script here and see if you can figure out what I'm doing wrong.

I've posted the working script with the part I cannot get to work is commented out. (lines 54-68)

If I uncomment the lines the script stops.

Any help?

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/207818-php-if-elseif-else/#findComment-1086380
Share on other sites

Sorry I think I misunderstood what you were asking before (thought you were asking to validate there was at least 1 check box ticked for an entry in the database).

 

Start again...

---

 

Right then rather than giving each check box a unique name, store them as an array:

 

<input type="checkbox" name="egroup[]" value="My check box" />

 

On the PHP side you can then spit out the error if the array is empty:

 

if (empty($_POST['egroup']))
{
    exit('You must select a group. No selection has been made');
}

 

The value for the check box is only posted if it's been checked.

Link to comment
https://forums.phpfreaks.com/topic/207818-php-if-elseif-else/#findComment-1086460
Share on other sites

Got it with this.

 

$nogroup = ((!$egroup1) && (!$egroup2) && (!$egroup3) && (!$egroup4) && (!$egroup5) && (!$egroup6));

$noequip = (!$equip);

if ($nogroup){

$errorMsg .= "--- Student Group. (No data was forwarded to the database.)</font>";

} else if($noequip){

$errorMsg .= "--- Quiz Name. (No data was forwarded to the database.)</font>";

} else {

 

 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/207818-php-if-elseif-else/#findComment-1088557
Share on other sites

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.