473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Viewing checkbox data with MySQL and PHP

Bee
Hi everyone,

I'm having trouble accessing a Mysql database containing checkbox data
that is posted from a form. I use the serialize function to store the
checkbox values in an array (in a column called "CHECKBOX").

Each row in the table has this format:

a:2:{i:0;s:7:"Peanuts";i:1;s:9:"Cows_milk";}

So I know the serialize function works fine. However, when using the
unserialize function to convert the data back into its single form. I
have no luck. The output for each row is "Array". Below is the code.
<?php //Code to connect to the database server
...
...

$query = "SELECT * FROM checkbox";
$doQuery = mysql_query($query);
$numrows = mysql_num_rows($doQuery);
if($numrows > 0)
{
while($checkbox = mysql_fetch_array($doQuery))
{
$check = unserialize($checkbox['CHECKBOX']);
echo($check);
}
}
?>

Can anyone offer any ideas about what I'm doing wrong?

Thanks in advance!

Bee.
Jul 20 '05 #1
4 3047
Bee wrote:
Can anyone offer any ideas about what I'm doing wrong?


Try:
echo $checkbox['CHECKBOX'];

If that prints the string that you have in the database, you have
problem in php side, if you prints something else, you have problem on
sql side.
Jul 20 '05 #2
Bee
> Try:
echo $checkbox['CHECKBOX'];

If that prints the string that you have in the database, you have
problem in php side, if you prints something else, you have problem on
sql side.


Thanks for replying.

I did try this and it printed out the strings in my database. So
therefore its a problem on the PHP side, as you commented. The thing
is, I cannot find out what the problem is i.e. why the output of each
string in the database is "Array" when I process the following:

$check = unserialize($checkbox['CHECKBOX']);
//code to loop array...
echo $check;

Any ideas are very welcome...(please!)

TIA.

Bee.
Jul 20 '05 #3
Hi Bee

Try using print_r($check) to view the contents of the $check array or try:

foreach ($check as $value) {
echo $value;
}

If the output of echo $value is still an array, loop through the $value
array as well.

foreach ($check as $value) {
foreach ($value as $innervalue) {
echo $innervalue;
}
}

--
Paul Barfoot
"Bee" <na******@gmail.com> wrote in message
news:62*************************@posting.google.co m...
Try:
echo $checkbox['CHECKBOX'];

If that prints the string that you have in the database, you have
problem in php side, if you prints something else, you have problem on
sql side.


Thanks for replying.

I did try this and it printed out the strings in my database. So
therefore its a problem on the PHP side, as you commented. The thing
is, I cannot find out what the problem is i.e. why the output of each
string in the database is "Array" when I process the following:

$check = unserialize($checkbox['CHECKBOX']);
//code to loop array...
echo $check;

Any ideas are very welcome...(please!)

TIA.

Bee.

Jul 20 '05 #4
Bee
Thanks very much! Now it works fine!

I guess I should've thought about looping through the actual array
itself. I ignored that each value returned an array, and expected
unserialize to do it all.

Cheers!

Bee.
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: RelaxoRy | last post by:
Reposted (not sure if got sent) I have results being displayed each with its own checkbox name "selected" and value "id". When someone checks a checkbox, and then continues to page through...
2
by: info | last post by:
novice.... i started a php site in dreamweaver and i try fill data into MySql database. i set up a page with a form and i can fill in all the fields. just for one field, i like to have...
3
by: elyob | last post by:
Okay, I'm about to add some checkboxes to a form, and then store the data in a column on a MySQL database. Just wanted to know best practice, at the moment I'm writing and thinking .. God that's...
6
by: Daz | last post by:
Hi everyone. Firstly, I apologise if this i not what you would call a PHP problem. I get quite confused as to what lives in which realm, so if this shouldn't be posted here, please suggest where...
29
by: Amer Neely | last post by:
I've got a dynamically built form with checkboxes for each element ( a list of file names in a directory). I need to grab only those checkboxes that are checked, so I can then delete those files. ...
1
by: inamul | last post by:
I want to select CheckBox based on data retrieved from mysql database table. Could anyone show me the simple way of doing it. Data store in table under colum "sectionOfInterest" is shown below...
1
by: inamul | last post by:
I want to select CheckBox based on data retrieved from mysql database table. Could anyone show me the simple way of doing it. Data store in table under colum "sectionOfInterest" is shown below...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
13
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.