unserialize()后无法获取数组

时间:2017-06-11 06:52:02

标签: php arrays

使用unserialize()后,我没有得到我的orignal数组。 我正在从数据库中检索数组并想要显示它。 我有两个数组,从复选框输入创建它们,然后我序列化()它们并将其存储在数据库中。

Create.php

<table>
  <tr>
  <td>Aadhar</td>
  <td><input type="checkbox" name="original[]" value="Aadhar"/></td>
  <td><input type="checkbox" name="xerox[]" value="Aadhar"/></td>
  </tr>
  <tr>
  <td>Pan Card</td>
  <td><input type="checkbox" name="original[]" value="Pan Card"/></td>
  <td><input type="checkbox" name="xerox[]" value="Pan Card"/></td>
  </tr>
  <tr>
  <td>Address</td>
  <td><input type="checkbox" name="original[]" value="Address"/></td>
  <td><input type="checkbox" name="xerox[]" value="Address"/></td>
  </tr>
  <tr>
  <td>Light Bill</td>
  <td><input type="checkbox" name="original[]" value="Light Bill"/></td>
  <td><input type="checkbox" name="xerox[]" value="Light Bill"/></td>
  </tr>
  <tr>
  <tr>
  <td><input type="submit" value="Submit" /></td>
  </tr>
</table>

Create2.php(此页面就像确认页面...在用户提交到数据库之前。)     

<?php
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$company = $_POST['company'];
$original_list = $_POST['original'];
$xerox_list = $_POST['xerox'];
?>

<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 $original_list ?>"  />
  <input type="hidden" name="xerox_list" value="<?php $xerox_list ?>" />
  <td>Documents Selected</td>
  <td>
    <?php
    echo "<b>ORIGINAL</b><br />";
    foreach($original_list as $value)
    {
      echo $value."<br />";
    }
    ?>
  </td>
  <td>
    <?php
    echo "<b>XEROX</b><br />";
    foreach($xerox_list as $value)
    {
      echo $value."<br />";
    }
    ?>
  </td>
</tr>
<tr>
  <td><input type="submit" value="Confirm" /></td>
</tr>
</table>
</form>
</body>

Create2.php(在数据库中插入)

$name = $_POST['name'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$company = $_POST['company'];

$original = serialize($_POST['original_list']);
$xerox = serialize($_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);

所以当我尝试反序列化并使用foreach显示数组时,这就是我得到的:

Warning: Invalid argument supplied for foreach() 

代码:

  $original = unserialize($rows['original']);
  foreach($original as $value)
  {
    echo $value."<br />";
  }

0 个答案:

没有答案