Reputation: 339
I am getting this error? What does it mean?
unserialize(): Error at offset 9 of 13 bytes
This is what I get after I serialize and store the array in database:
a:3:{i:0;s:6:
And at the time of unserialize, it gives the error! What should I do? I want my original array back and want to display it.
I have tried other post, like basencoder/decode, but thats not working too..
Create1.php(passing serialized array to next page through hidden input)
<form action="create2.php" method="POST">
<table cellpadding="10">
<tr>
<td>Name</td>
<td><input type="text" name="name" value="<?php echo $name; ?>" readonly="readonly" ></td>
</tr>
<tr>
<td>Mobile</td>
<td><input type="text" name="mobile" value="<?php echo $mobile; ?>" readonly="readonly" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value="<?php echo $email; ?>" readonly="readonly" /></td>
</tr>
<tr>
<td>Company</td>
<td><input type="text" name="company" value="<?php echo $company; ?>" readonly="readonly" /></td>
</tr>
<tr>
<input type="hidden" name="original_list" value="<?php echo serialize($original_list); ?>" />
<input type="hidden" name="xerox_list" value="<?php echo serialize($xerox_list); ?>" />
</tr>
<tr>
<td><input type="submit" value="Confirm" /></td>
</tr>
</table>
</form>
Create2.php(getting and storing serialized array in database)
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$company = $_POST['company'];
$original = $_POST['original_list'];
$xerox = $_POST['xerox_list'];
echo $sql = "INSERT INTO users (name,mobile,email,company,original,xerox)
VALUES ('$name','$mobile','$email','$company','$original','$xerox')";
mysqli_query($con,$sql);
Upvotes: 0
Views: 2452
Reputation: 40653
I'm not sure it's safe to use binary strings in HTML (HTTP is a text protocol after all). I suggest using JSON encoding instead of serialization.
<input type="hidden" name="original_list" value="<?php echo json_encode($original_list); ?>" />
<input type="hidden" name="xerox_list" value="<?php echo json_encode($xerox_list); ?>" />
When accessing the entries you can then do:
json_decode($row['original'],true); //you get the idea
Upvotes: 1