romio Posted April 5, 2006 Share Posted April 5, 2006 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:[code] $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);[/code]and this is my form_edit() function which loads data row from my db:[code] $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>[/code] Quote Link to comment Share on other sites More sharing options...
TheUkSniper Posted April 5, 2006 Share Posted April 5, 2006 not too sure what ur asking but thats the code below u could use to disable a radio box to be checkedso 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[code]<input type='radio' name='product' <? if (isset($status == 0)) echo "value='disable'" ?> class='style5'>[/code] Quote Link to comment Share on other sites More sharing options...
romio Posted April 6, 2006 Author Share Posted April 6, 2006 the disable radion is always checked no matter what the value of $enabled would be:[code] 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'> 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> [/code] Quote Link to comment 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.