Jump to content


Photo

Enable and Disable radio button


  • Please log in to reply
2 replies to this topic

#1 romio

romio
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 05 April 2006 - 01:29 PM

In my database I do have a 'status' field which have the value 1 for enable product and 0 for disable product, when the user click on edit product I do have a form that loads a form with the specified Id, my only problem is the radio option which I don’t know how to set one of them to be true if it has a value of 1.

Some part of my edit_product() function which is used to edit a product:


    $category = $_GET['nodeid'];
    $product_id = $_GET['product_id'];
    $name = $_POST['product_name'];
    $description = $_POST['description'];
    $price = $_POST['price'];
    $in_stock = $_POST['in_stock'];
    $brief_desc = $_POST['brief_description'];
    $product_code = $_POST['product_code'];
    $upload_folder = "images/product_thumbnail";     
    $image = $fileName = $_FILES['uploaded']['name'];

    switch($_POST['status'])        
      {                        
          case 'enable':                       
              $status = 1;
              break;
          
          case 'disable':                           
              $status = 0;
              break;
      }

       $edit_product = "UPDATE product SET name='$name', description='$description', price='$price', in_stock='$in_stock', enabled='$status', brief_description='$brief_desc', product_code= '$product_code', thumbnail='$image' WHERE product_id=$product_id";
    $edit_product_query = mysql_query($edit_product);

and this is my form_edit() function which loads data row from my db:

    $catID = $_GET['nodeid'];
    $product_id = $_GET['product_id'];
    $edit_product = "SELECT * FROM product WHERE product_id = $product_id";
    $edit_product_query = mysql_query($edit_product);
    $edit_product_display_rows = mysql_num_rows($edit_product_query);

    while($row = mysql_fetch_array($edit_product_query))
    {
        $name = $row['name'];
        $description = $row['description'];
        $price = $row['price'];
        $in_stock = $row['in_stock'];
        $item_sold = $rows['items_sold'];
        $enabled = $row['enable'];
        $brief_description = $row['brief_description'];
        $product_code = $row['product_code'];
    }

    echo"
        <table border='0' align=center cellspacing='0' cellpadding='0' width='100% height='100%'>
        <tr>
            <td>
                <form name='' method='post' action='?sec=9&treeviewid=treeid&nodeid=$catID&product_id=$product_id' enctype='multipart/form-data'>
                    <table border='0' cellspacing='2' cellpadding='2' border='0' height='100%' align='center' width='95%'>
                        <tr>
                             <td height='20' colspan=3></td>
                        </tr>
                        <tr>
                             <td width='178'  class='style13' height='33'> Product Name : *</td>
                             <td width='413' class='style12' colspan='2' height='33'>
                            <input type='text' name='product_name' value='$name' size='22' maxlength='160' /></td>
                        </tr>
                             ............
                             ............
                        <tr>
                             <td width='178'  class='style13' height='33'> Display:</td>
                             <td width='413' class='style12' colspan='2'>
                             Enable<input type='radio' name='status' value='enable' class='style5'>
                             Disable<input type='radio' name='status' value='disable' class='style5'></td>
                        </tr>


#2 TheUkSniper

TheUkSniper
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 05 April 2006 - 07:58 PM

not too sure what ur asking but thats the code below u could use to disable a radio box to be checked

so if the variable $status = 0... php would write into the code disabling the radio box.. no else is needed as by default it should be enabled

<input type='radio' name='product' <? if (isset($status == 0)) echo "value='disable'" ?> class='style5'>


#3 romio

romio
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 06 April 2006 - 08:36 AM

the disable radion is always checked no matter what the value of $enabled would be:
   echo $enabled;
   echo"
      <table border='0' align=center cellspacing='0' cellpadding='0' width='100% height='100%'>
      <tr>
         <td>
            <form name='' method='post' action='?sec=9&treeviewid=treeid&nodeid=$catID&product_id=$product_id' enctype='multipart/form-data'>
               <table border='0' cellspacing='2' cellpadding='2' border='0' height='100%' align='center' width='95%'>
                  <tr>
                      <td height='20' colspan=3></td>
                  </tr>

                                         ......................................
                                         ......................................
<td width='178'  class='style13' height='33'>&nbsp;Display:</td>
<td width='413' class='style12' colspan='2'>
Enable <input type='radio' name='status' value='enable'  class='style5' if($enabled == 1){ checked='checked'}>
Disable<input type='radio' name='status' value='disable' class='style5' if($enabled == 0){ checked='checked'}> </td> 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users