MySQL Forums
Forum List  »  PHP

Inserting heckboxes values into table column
Posted by: Zaur Rzayev
Date: November 08, 2014 05:53AM

Hello.
Could you please help to solve this out.

Lets say we have form
<html>
<form method="post" action="test.php">
Some label: <br/>
<input type="checkbox" name="ids[]" value="1">1<br>
<input type="checkbox" name="ids[]" value="2">2<br>
<input type="checkbox" name="ids[]" value="3">3<br>
<input type="checkbox" name="ids[]" value="4">4 <br>
<input type="checkbox" name="ids[]" value="5">5<br>
<input type="checkbox" name="ids[]" value="6">6 <br>
<input type="checkbox" name="ids[]" value="7">7<br>
<input type="checkbox" name="ids[]" value="8">8 <br>
<input type="submit" name="submit" value="submit">
</form>
</html>

<?php
And PHP Script
//MySQL Connection
include ('config.php');
//Количество проставленных птичек
$checked_arr = $_POST['ids'];
$count = count($checked_arr);
//Цикл
for ($x=1; $x<=$count; $x++) {
$query="INSERT INTO crewchange (arrivals) VALUES ('" . $x . "')";
mysqli_query($con, $query) or die (mysql_error() );
}
echo "Complete";
?>


For now it inserts the values 1 2 3 4 depending on total number of checked boxes. How to make it insert the values of checkboxes ?

Thank you

Options: ReplyQuote


Subject
Written By
Posted
Inserting heckboxes values into table column
November 08, 2014 05:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.