multiple checkbox storing and retrieving

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: multiple checkbox storing and retrieving

Post by Celauran »

['co_app'] is not a variable. What variable contains the data you've retrieved from the DB?
User avatar
jaad
Forum Commoner
Posts: 95
Joined: Fri Jan 03, 2014 5:30 am
Location: Vancouver Canada

Re: multiple checkbox storing and retrieving

Post by jaad »

the field in the database is called co_app. I was referring to the $co-app in my last post. as for what I am retrieving from the database I am not retrieving anything. I have the error message that I;ve posted in my previous post
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: multiple checkbox storing and retrieving

Post by Celauran »

jaad wrote:I already have $co_app = implode(',', ['co_app']); on the line above. Shouldn't I give the explode function another variable name?
Oh, I see. This on the same page where the form was initially submitted. In that case, you can use $_POST directly.

Code: Select all

<input type="checkbox" name="co_app[]" value="roommate" <?= in_array('roommate', $_POST['co_app']) ? 'checked="checked"' : ''; ?>>
User avatar
jaad
Forum Commoner
Posts: 95
Joined: Fri Jan 03, 2014 5:30 am
Location: Vancouver Canada

Re: multiple checkbox storing and retrieving

Post by jaad »

nope.... still the same thing I get the following:

Code: Select all

Co-Application:
Notice: Undefined index: co_app in C:\xampp\htdocs\lar\settings.php on line 288

Warning: in_array() expects parameter 2 to be array, null given in C:\xampp\htdocs\lar\settings.php on line 288
> Spouse Notice: Undefined index: co_app in C:\xampp\htdocs\lar\settings.php on line 289

Warning: in_array() expects parameter 2 to be array, null given in C:\xampp\htdocs\lar\settings.php on line 289
> Roommate Notice: Undefined index: co_app in C:\xampp\htdocs\lar\settings.php on line 290

Warning: in_array() expects parameter 2 to be array, null given in C:\xampp\htdocs\lar\settings.php on line 290
> None 
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: multiple checkbox storing and retrieving

Post by Celauran »

Code: Select all

<input type="checkbox" name="co_app[]" value="roommate" <?= (array_key_exists('co_app', $_POST) && in_array('roommate', $_POST['co_app'])) ? 'checked="checked"' : ''; ?>>
User avatar
jaad
Forum Commoner
Posts: 95
Joined: Fri Jan 03, 2014 5:30 am
Location: Vancouver Canada

Re: multiple checkbox storing and retrieving

Post by jaad »

well it got rid of the error messages but no values get saved to the database now. none comes back either. I think my explode function() is broken. I wonder if they fix that at the garage at the corner by my place lol. I really thank you for trying man, you are going beyond the call of duty here.
Post Reply