jerk Posted January 24, 2008 Share Posted January 24, 2008 I'm trying to craete a simple website customer search for my customers I have got the main search working but now would like to add what Stock they currently stock. We have approx 4 items we manufacture which come in no more than 4 sizes each. My initial thoughts were to have multiple checkboxes for the website administrator can choose what stock they stock. I have created a table with 2 columns Customerid and stock The customerid will be the link back to the customer in the main customer table. I have created this script which inserts the stock to the table sucessfully. $customer = $customerid; $protection = $_POST['protection']; function print_selected_values($custid, $area_array) { foreach($area_array as $protect){ $query = "insert into customers_stock(protection,customerid)values('$protect','$custid')"; $result = mysql_query($query) or die ("query not made"); } } print_selected_values($customer,$protection); The mysql table looks like protection customerid 0625c25 164 0625c100 164 0625h50 164 0625h100 164 1250c50 164 1250h50 164 1250m25 164 My problem is putting the info from mysql to an edit form. I would like to have a checkbox to be checked when ever a product code is in the database. I have created the checkboxes with the same name as the protection in the table. The mess I came up with was $stockedresult = @mysql_query("SELECT protection FROM `customers_stock` WHERE `customerid`=".$_GET['id']." LIMIT 30"); $stockedrow = mysql_fetch_array($stockedresult); $protection = $stockedrow['protection']; <td align = 'left'><label> <input type='checkbox' name='0625c25' id ='protection' checked='if ($protection = '0625c25') {echo 'checked';}'> </label></td> <td align = 'left'><label> <input type='checkbox' name='0625c50' id ='protection' checked='if ($protection = '0625c50') {echo 'checked';}'> </label></td> <td align = 'left'><label> <input type='checkbox' name='0625c100' id ='protection' checked='if ($protection = '0625c100') {echo 'checked';}'> </label></td> Can anyone give me any pointers? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/87558-php-mysql-checkboxes/ Share on other sites More sharing options...
revraz Posted January 24, 2008 Share Posted January 24, 2008 I'm a bit confused on the situation. So you want to put a check box next to the list where there are codes in the DB, but the list is generated from the codes that already exist? So actually, you are putting a check box next to everyone? Also, is the Protection ID unique? If so, when you list the items, just put a link under the protection id, have the link reference a edit routine like protection.php?edit=0625c25 and then use a $_GET['edit'] to retrieve it and pull it into a form to edit. Is that along the lines you were thinking? Quote Link to comment https://forums.phpfreaks.com/topic/87558-php-mysql-checkboxes/#findComment-447823 Share on other sites More sharing options...
jerk Posted January 24, 2008 Author Share Posted January 24, 2008 A checkbox for every stocked item. the checkbox will be checked if the stock exists in the stock database. The ID will be unique as this is the link between the customer and the stock. so in the example customer 164 stocks 7 items The edit form will be something like form textbox * 5 for name and address 20 checkboxes so the administrator can edit what stock they stock. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/87558-php-mysql-checkboxes/#findComment-447833 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.