This is my the search code i have tried it works well with the fiels stores as string in the database. But i have stored the qualification and specialization as int in database. Each selected value has a unique id. I am not able to search by qualification and specialization fields. If i enter the qualification name in text box then it never displays anything. How can i do it for values stored as int in the table.
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- </head>
- <body>
- <?php
- $error="";
- if (!isset($_POST['Submit'])) {
- // form not submitted
- ?>
- <form action="<?=$_SERVER['php_SELF']?>" method="post">
- search <input type="text" name="search"><br>
- <select size="1" name="dropdown">
- <option value="" selected>search By...</option>
- <option value="YearsExp">Experience</option>
- <option value="FunctionalArea">Functional Area</option>
- <option value="Qualification">Qualification</option>
- <option value="Specialization">Specialization</option>
- <option value="KeySkills">Key Skills</option>
- <option value="Institute">Institute</option>
- </select>
- <input type="Submit" value="Submit" name="Submit">
- </form>
- <?php
- }
- else {
- // form submitted
- // set server access variables
- $host = "localhost";
- $user = "root";
- $pass = "database";
- $db = "skills_portfolio";
- $search = empty($_POST['search'])? die ($error= "Enter search Criteria") : mysql_escape_string($_POST['search']);
- $dropdown = empty($_POST['dropdown'])? die ($error= "Select from dropdown") : mysql_escape_string($_POST['dropdown']);
- // Open Connection
- $connect = mysql_connect($host, $user, $pass) or die ("Unable to connect to host");
- //Select Database
- mysql_select_db($db) or die ("Unable to connect to database");
- //Create Query
- $query = "SELECT * FROM userdetails WHERE $dropdown='$search'" or die (mysql_error());
- $data = mysql_query($query) or die(mysql_error());
- echo "<b><center>Database Output</center></b><br><br>";
- while($info=mysql_fetch_array($data)){
- //Print it out to page
- echo "".$info['UserName'] . " <BR>";
- }// end of while
- mysql_close($connect);
- }
- ?>
- </body>
- </html>