•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,973 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,819 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2392 | Replies: 4 | Solved
![]() |
•
•
Join Date: Sep 2007
Posts: 31
Reputation:
Rep Power: 2
Solved Threads: 1
I am trying to store the contents of checkboxes in a field in a mysql database and retireve them later...
(the "..." means that there is other information, yes those are confirmed working, inserted as well)
This is what I use to retrieve the data:
(obviously, the .'s mean other - confirmed working - code)
Problem is that the $value comes out as "array"...what the heck am I doing wrong?
Thanks!
html Syntax (Toggle Plain Text)
<input type="checkbox" name="days[]" class="other" value="Monday" /> <label class="left">Monday</label> <br /> <input type="checkbox" name="days[]" class="other" value="Tuesday" /> <label class="left">Tuesday</label> <br /> <input type="checkbox" name="days[]" class="other" value="Wednesday" /> <label class="left">Wednesday</label> <br /> <input type="checkbox" name="days[]" class="other" value="Thursday" /> <label class="left">Thursday</label> <br /> <input type="checkbox" name="days[]" class="other" value="Friday" /> <label class="left">Friday</label> <br /> <input type="checkbox" name="days[]" class="other" value="Saturday" /> <label class="left">Saturday</label> <br /> <input type="checkbox" name="days[]" class="other" value="Sunday" /> <label class="left">Sunday</label> <br />
php Syntax (Toggle Plain Text)
$days = implode(",",$_POST['days']); . . mysql_query("INSERT INTO users (..., days, ...) VALUES (.., '$days', ..)") or die("something went wrong during the registration. MySQL said: ".mysql_error());
(the "..." means that there is other information, yes those are confirmed working, inserted as well)
This is what I use to retrieve the data:
php Syntax (Toggle Plain Text)
$result = mysql_query("SELECT * FROM users where verified = 0"); while($info = mysql_fetch_array($result, MYSQL_ASSOC)) { . . . $days = explode(",", $info['days']); foreach ($days as $value){ echo $value; echo "<br/>"; } . . . }
(obviously, the .'s mean other - confirmed working - code)
Problem is that the $value comes out as "array"...what the heck am I doing wrong?
Thanks!
•
•
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation:
Rep Power: 3
Solved Threads: 68
try to have a counter so you can display your data:
php Syntax (Toggle Plain Text)
$a=0; foreach ($days as $value){ $a=$a+1; } for($i=0;$i<$a;$i++) { echo $days[$a]; echo "<br/>"; }
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
http://ryantetek.wordpress.com
•
•
Join Date: Sep 2007
Posts: 31
Reputation:
Rep Power: 2
Solved Threads: 1
Ok. I just tried that..same thing...
when I echo a$ (after the first foreach), it gives a value of 1
so then I echo $days[0] (the first record)
its gives a value of 'array'
Got frustrated, so I even tried to populate $days like this(starting with an empty array and adding each value the array one by one, then implode to a single comma-delimited string...seems logical) -- ended up with same dang result though...grrrr
I guess my next step is to take them out of the checkbox array, give each box a seperate name and add them to an array manually in the code.
I think its just a matter of missing something simple...guess I am just overlooking it....
when I echo a$ (after the first foreach), it gives a value of 1
so then I echo $days[0] (the first record)
its gives a value of 'array'
Got frustrated, so I even tried to populate $days like this(starting with an empty array and adding each value the array one by one, then implode to a single comma-delimited string...seems logical) -- ended up with same dang result though...grrrr
php Syntax (Toggle Plain Text)
$days_array = array(""); foreach ($_POST['days'] as $val2){ $days_array[] = $val2; } $days = implode(",",$days_array);
I guess my next step is to take them out of the checkbox array, give each box a seperate name and add them to an array manually in the code.
I think its just a matter of missing something simple...guess I am just overlooking it....
•
•
Join Date: Sep 2007
Posts: 31
Reputation:
Rep Power: 2
Solved Threads: 1
Here's what confusing me...
when I store the imploded array, it SHOULD be a comma-delimated string of the values...BUT, it appears to have the value 'ARRAY', which tells me that the implode didn't work, i.e. the $_POST['days'] array stored not as a string of values seperated by commas, but as an array(hence the value ARRAY showing up in the $data field).
Am I missing a step somewhere when storing the field??
when I store the imploded array, it SHOULD be a comma-delimated string of the values...BUT, it appears to have the value 'ARRAY', which tells me that the implode didn't work, i.e. the $_POST['days'] array stored not as a string of values seperated by commas, but as an array(hence the value ARRAY showing up in the $data field).
Am I missing a step somewhere when storing the field??
Last edited by verbob : Nov 28th, 2007 at 2:58 pm.
•
•
Join Date: Sep 2007
Posts: 31
Reputation:
Rep Power: 2
Solved Threads: 1
heres a stupid mistake...LOL
When I created the form with the checkboxes, the post was to a file called register.php...I changed it to the name of this file register2.php, but amoungst my edits, I inadvertently reset it back to register.php, hence it was posting from the old file not the new one and thus giving me the error(s).
Gawd...I had the code right many many hours ago but one stupid CTRL-Z too many in Dreamweaver and it messed it all up arrrgh haha
Thanks guys
When I created the form with the checkboxes, the post was to a file called register.php...I changed it to the name of this file register2.php, but amoungst my edits, I inadvertently reset it back to register.php, hence it was posting from the old file not the new one and thus giving me the error(s).
Gawd...I had the code right many many hours ago but one stupid CTRL-Z too many in Dreamweaver and it messed it all up arrrgh haha
Thanks guys
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Previous Thread: Help on form validation requested.
- Next Thread: How to expire pages? (prevent clicks on old ones)


Linear Mode