Jump to content

Recommended Posts

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

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/87558-php-mysql-checkboxes/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/87558-php-mysql-checkboxes/#findComment-447823
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/87558-php-mysql-checkboxes/#findComment-447833
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.