<form method="POST">
<table>
<?php
$query = "SELECT id,itemName,itemId FROM services";
$result = mysql_query($query) or die("Can't create query: " . mysql_error());
while ($row = mysql_fetch_array($result))
{
echo "
<tr>
<td>$row[itemName]</td>
<td><input type=\"hidden\" name=\"item[]\" value=\"$row[itemId]]\"><input type=\"text\" name=\"value[]\" ></td>
<td><input type='checkbox' name='checkbox[]' value='$row[id]'></td>
</tr>";
}
?>
</table>
<input type="submit" name="save" value="Save" />
</form>
<?php
if (isset($_POST['save']))
{
if ($_POST['checkbox'] == 0)
{
echo 'no items selected';
} else
{
// selected field values where checked
foreach ($_POST['checkbox'] as $id)
{
// grab $_POST info create vars
$userId = $_SESSION['userid'];
$itemId = $_POST['item'];
$itemValue = $_POST['value'];
/*
I have also used a for loop here to count the posted items so the vars would be $itemId[$i],$itemValue[$i]. Extracting as array from form.
They would not match up.
*/
// $queries is so that it enters multiple rows at once.
$queries = array();
$queries[] = "('$userId','$itemId','$itemValue')";
// $queries[] = "('$userId','$itemId[$id]','$itemValue[$id]')";
$piece = implode(", ", $queries);
$query = "INSERT INTO cust_services (user,item,value) VALUES $piece";
$result = mysql_query($query) or die(mysql_error());
}
}
}
?>
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.