pak4eva Posted March 9, 2007 Share Posted March 9, 2007 Hi guys, i just wnated to know how i can use php script for my form that i have created in html, basically the code is below, what i want to do is when a user selects metal then it should display metals from the database, if metalloids selected then again it should retrieve that info from database..... <form name="input" action="type.php" method="get"> <select name=group> <option>Select Type</option> <option>Metals</option> <option>Metalloids</option> <option>Non-Metals</option> </select> <input name="search2" type="submit" value="search"> </form> If possbile can someone post the actual script please. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/41951-forms-in-php/ Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 So you want to search the database with a drop down form and show those records selected? Quote Link to comment https://forums.phpfreaks.com/topic/41951-forms-in-php/#findComment-203380 Share on other sites More sharing options...
JasonLewis Posted March 9, 2007 Share Posted March 9, 2007 first your would need to give each option a value that is the same as what it will be in the database and change the method to POST instead of GET, or you could use GET but change all the $_POST below to $_GET in the page type.php you would have code sort of like the below: if(isset($_POST['search2'])){ //check to make sure submit was pressed $option = $_POST['group']; $query = "SELECT * FROM `table_name` WHERE `type`='{$option}'"; $sql = mysql_query($query) or die("Error: ".mysql_error()."<br>SQL: ".$query); if($sql){ //make sure query worked $data = mysql_fetch_array($sql); echo $data['info']; //echo out the type information. } } you can build off that if you need to. Quote Link to comment https://forums.phpfreaks.com/topic/41951-forms-in-php/#findComment-203384 Share on other sites More sharing options...
tauchai83 Posted March 9, 2007 Share Posted March 9, 2007 in type.php $select=$_POST['group']; $sql="SELECT * FROM db WHERE xx='$select'"; $result=mysql_query($sql); mysql_fetch_assoc($result); and so on...depend what you want to do...this is a clue can help you go to correct direction. thanks. Hope this help Quote Link to comment https://forums.phpfreaks.com/topic/41951-forms-in-php/#findComment-203388 Share on other sites More sharing options...
pak4eva Posted March 9, 2007 Author Share Posted March 9, 2007 Yes... Quote So you want to search the database with a drop down form and show those records selected? Quote Link to comment https://forums.phpfreaks.com/topic/41951-forms-in-php/#findComment-203390 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.