简体   繁体   中英

how to read/see stored array[] mysql php

i have the next files to store an array[] into a mysql database. Now i would like to create a file to see the stored data, as an info file....like a table with the results or something.

in phpmyadmin database i see the stored data as:

a:2:{i:0;s:10:"sentra b15";i:1;s:10:"sentra b13";}

thanks for your time

index.php

<html>
<body>


<form action="insert3.php" method="post">
Firstname: <input type="text" name="firstname[]"> <br>
Firstname 2: <input type="text" name="firstname[]"> <br>
Firstname 3: <input type="text" name="firstname[]"> <br>
Firstname 4: <input type="text" name="firstname[]"> <br>
<input type="submit">
</form>


</body>
</html>

insert.php

<?php
$con=mysqli_connect("localhost","inputmultiplicad","inputmultiplicado","inputmultiplicado");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }








$data= $_POST['firstname'];
$values= serialize($data);

$sql="INSERT INTO input_field (firstname)
VALUES
('$values')";




if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "1 record added";


mysqli_close($con);
?>

It's the result of php serialize function. Use unserialize function to decode it:

echo unserialize($str);

i think in your case the solution is this:

$data[0]; is going to be your first index or value that you inserted.

$data[1]; is going to be your secind index or value that you inserted.

and there for.....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM