marciokoko
marciokoko

Reputation: 4986

How to insert many records into a table from HTML form using php MySQL?

I have a form with 640 cards each with a checkbox so the user can mark the ones he owns.

I'm wondering how to write the update SQL statement to take each of the 640 card ids and insert/update into the db.

Each row is created by this code:

echo "<td>"?>
         <form name="some form" action="editform.php" method="post">
         <input type="checkbox" name="<?php 
echo $row['stickerID'] ?>" value=" <?php echo $row['stickerStatus'] ?> ">
         <?php "</td>";
echo "</tr>"; 
}

I know I need some kind of for each loop in php. But how do I get the 640 individual checkboxes from the post?

Upvotes: 0

Views: 110

Answers (1)

user557846
user557846

Reputation:

suggest you name them like so

<input type="checkbox" name="stickerid[<?php 
echo $row['stickerID'] ?>]" value=" <?php echo $row['stickerStatus'] ?> ">

then you can loop through the $_POST['stickerid'] array

foreach($_POST['stickerid'] as $k=>$v ){
//code
//$k=id
//$v=status
}

Upvotes: 2

Related Questions