Search the Community
Showing results for tags 'array[]'.
-
hi, 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); ?>
- 2 replies
-
- array[]
- serialized
-
(and 3 more)
Tagged with:
-
im working on a project but first i would to understand one thing. i have 2 input type text field with name="firstname[]" as an array (in the example im working with no jquery but it will be generated dinamically with it) and cant make it to mysql. here is what i have: index.php <html> <body> <form action="insert.php" method="post"> Firstname: <input type="text" name="firstname[]"> <br> Firstname 2: <input type="text" name="firstname[]"> <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(); } $sql="INSERT INTO input_field (firstname) VALUES ('$_POST[firstname]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?> the question is: how can i send the firstname[] array to the mysql database?