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
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}'");

     }

}


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.