Orasion Posted March 7, 2012 Share Posted March 7, 2012 So, it's me again. Hope you dont mind I try to fetch data from mysql and list it to select option like this <td>Category</td> <td>: <select name="category"> <?php $query = "SELECT DISTINCT category FROM dress"; $sql = mysql_query($query); while($result = mysql_fetch_array($sql)){ echo "<option value='".$result['category']."'>".$result['category']."</option>"; } ?> <option value="other">New Category --></option> </select><input type="text" name="categoryOther"></td> </tr> ...and success. BUT, when I try to echo submitted value it return nothing this is the code to process above form if(isset($_POST['categoryOther'])){ $category = $_POST['categoryOther']; } else { $category = $_POST['category']; } if(isset($_POST['subcategoryOther'])){ $subcategory = $_POST['subcategoryOther']; } else { $subcategory = $_POST['subcategory']; } echo "category : ".$category."<br>"; What did I do wrong here? Quote Link to comment https://forums.phpfreaks.com/topic/258435-problem-submitting-value-from-dynamic-option/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 7, 2012 Share Posted March 7, 2012 type="text" form fields are set, even if they are empty. if(isset($_POST['categoryOther'])){ will always be true any time the form has been submitted. Perhaps you want to test if $_POST['categoryOther'] is empty or if it is equal to an empty string? Quote Link to comment https://forums.phpfreaks.com/topic/258435-problem-submitting-value-from-dynamic-option/#findComment-1324736 Share on other sites More sharing options...
Orasion Posted March 7, 2012 Author Share Posted March 7, 2012 I change my code to this one if(strlen($_POST['categoryOther'] = 0)){ $category = $_POST['category']; } else { $category = $_POST['categoryOther']; } ..and success to submit my select category option. BUT, cannot submit input from categoryOther. I'll think another way to submit one of them. thanks for your suggestion, PFMaBiSmAd. EDIT : silly me, it is as simple as this if($_POST['category'] == "other"){ $category = $_POST['categoryOther']; } else { $category = $_POST['category']; } Now, both works. Quote Link to comment https://forums.phpfreaks.com/topic/258435-problem-submitting-value-from-dynamic-option/#findComment-1324741 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.