Help with unserialize array()

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

dv_evan
Forum Commoner
Posts: 42
Joined: Wed Apr 09, 2008 8:23 am

Re: Help with unserialize array()

Post by dv_evan »

Arraya:2:{i:0;sa:3:{i:0;sa:3:{i:0;sN;N;N;N;N;N;N;N;N;N;

Above is what the values look like in the DB
dv_evan
Forum Commoner
Posts: 42
Joined: Wed Apr 09, 2008 8:23 am

Re: Help with unserialize array()

Post by dv_evan »

Aceconcept,

My code is as above in previous message, nothing fancy, just need it to work.

See my code above.

thanks Dave
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Re: Help with unserialize array()

Post by mattcooper »

The serialized data you've posted here does not unserialize - it appears to be corrupt. Can you please re-post, providing:
  • - A text echo of the array
    - The raw serialized array string you're storing
    - The string as returned by your query
    - The properties of the field you are storing this in
A correctly serialized array should look like this:

Code: Select all

a:7:{i:0;s:4:"Page";i:1;s:4:"User";i:2;s:10:"PageModule";i:3;s:4:"News";i:4;s:8:"Location";i:5;s:7:"Content";i:6;s:12:"UserLocation";}
Yours looks like this:

Code: Select all

Arraya:2:{i:0;sa:3:{i:0;sa:3:{i:0;sN;N;N;N;N;N;N;N;N;N;
When you post here, try to provide as much info as possible (from my experience in the early days!) for us to help you debug ;)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Help with unserialize array()

Post by John Cartwright »

The serialized values are still being truncated. Compare the format your showing us to this:

Code: Select all

echo serialize(array('foo' => 'bar'));
Where is the code inserting the contents of the database? Can you post your table structure?

EDIT | Beaten to it :wink:
dv_evan
Forum Commoner
Posts: 42
Joined: Wed Apr 09, 2008 8:23 am

Re: Help with unserialize array()

Post by dv_evan »

Thanks Again,
Sorry if I am confusing you all more than I am helping myself.

Ok from Start, here is the HTML form that will collect the checkbox data.

Code: Select all

<form action='".$_SERVER['php_self']."' method='post'>
<td width='25%'><input type=checkbox name=box[] value='Mathew'></td>
<td width='25%'>&nbsp;Mathew</td>
<td width='25%'><input type=checkbox name=box[] value='Reid'></td>
<td width='25%'>&nbsp;Reid</td>
<td width='25%'><input type=checkbox name=box[] value='Simon'></td>
<td width='25%'>&nbsp;Simon</td>
<tr><th colspan=2><input type='submit' name='submit' value='Register'></th></tr>
 
</form>
 
Now here is the PHP code that I inputted these data into the database:

Code: Select all

 
<?
include ("Conn.php");
 
$box=serialize($_POST['box']);
 
$insert = "INSERT INTO Exhibitors (Exh_Type)
VALUES ('$box')";
 
mysql_query($insert);
?>
 
 
All I need is to output this in a readable form.

Database info:
TableName: Exhibitors
FieldName: Exh_Type
DataType: Well you guys had ask for me to change to 'TEXT'

Let me know if you need any other information for you to assist me.
Dave.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Help with unserialize array()

Post by John Cartwright »

I meant what does

Code: Select all

SHOW CREATE TABLE Exhibitors
show?
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Re: Help with unserialize array()

Post by mattcooper »

I'll say again: if you can post the data from

Code: Select all

serialize($_POST['box'])
And the data that comes back from your query, they can be compared... therein lies your problem I think.
Post Reply