Jump to content

Form processing and checkboxes


Schlo_50

Recommended Posts

Hello again guys!

 

I have a script ritten in php which calls a list of products from my database and echo's out each row that i need. (Item number, name, description and price etc.) After each row of my ms access database i have also echo'ed out a checkbox, which when clicked by the user, i want to send the item number of that articular product into my database.

 

The problem is i have no idea how to 'catch/'collect' the $ProductId variable value that correlates with the correct checkbox.

 

This is my code which outputs the database results and also, my checkboxes:

 

<?php
$sql2 = odbc_exec($odbc, "SELECT * FROM Product1 ORDER BY CategoryName") or die (odbc_errormsg());

$prevCat='';
while($row = odbc_fetch_array($sql2))
{
$Category = $row["CategoryName"];
$ProductId = $row["ProductId"];
$ProductName = $row["ProductName"];
$Price = $row["Price"];

// has category changed
// if so, print it
if ($Category != $prevCat)  {
	echo "<h2>$Category</h2>";
}
echo  'Item Code: ', $ProductId, '<br/>Item Name:  ', $ProductName, '<br/><br/>Price: £', $Price, '<input name="code" type="checkbox" value="" /><br/><br/>';

$prevCat = $Category;
}
?>

 

This code outputs for example:

 

Item Code: 17

Item Name: Item Three

ProductName: Blues

Price: £10.99

|CheckBox|

 

Hope somebody can help me, thanks alot guys!

Link to comment
https://forums.phpfreaks.com/topic/77432-form-processing-and-checkboxes/
Share on other sites


echo  "

     Item Code: {$ProductId}<br/>
     Item Name: {$ProductName}<br/><br/>
     Price: £{$Price} <input name="products[{$ProductId}]" type="checkbox"/><br/><br/>

";

 


if (!empty ($_POST['products'])){

     foreach ($_POST['products'] as $product){

          mysql_query ("INSERT INTO your_table SET some_field='{some_value}'");

     }

}


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.