Jump to content

forms in php


pak4eva

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
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.