filter result by selection

Codes here !

Moderators: macek, egami, gesf

Post Reply
kanonyqkaskdn

filter result by selection

Post by kanonyqkaskdn » Mon Apr 08, 2013 6:09 am

I try to show some data by dropdown option from mySQL

when the user choose option United states and click submit, the page will go to the next page and show the data only for United states

here is my code for test.html

Code: Select all

<body>
	<form action="showDB.php" method="post">
	<table border="0">
	<tr>
		<th>test</th>
	</tr>
	<tr>
		<td>Select Foreign Agent Country</td>
		<td></td>
		<td>
		<select>
		<option name="country" value="US">United States</option>
		<option name="country" value="AUD">Australia</option>
		</select> 
		</td>
	  </tr>
		<td>
		<button type="submit" name="btn_submit"><a href="showDB.php">Click</a></button>
		</td>
	</table>
	</form>

</body>
here is my second page showDB.php

Code: Select all

<?php
//connect to server
$connect = mysql_connect("localhost", "root", "");

//connect to database
//select the database
mysql_select_db("asdasd");

//query the database
$query = mysql_query("SELECT * FROM auip_wipo_sample");
if($_POST['country'] == 'US') {  
    // query to get all US records  
    $query = mysql_query("SELECT * FROM auip_wipo_sample WHERE wipo_applicant1_country='US'");  
}  
elseif($_POST['country'] == 'AUD') {  
    // query to get all AUD records  
    $query = mysql_query("SELECT * FROM auip_wipo_sample WHERE wipo_applicant1_country='JP'");  
} else {  
    // query to get all records  
    $query = mysql_query("SELECT * FROM auip_wipo_sample");  
}  
//fetch the result
Print "<table border cellpadding=3>"; 
while($row = mysql_fetch_array($query))
{
	Print "<tr>"; 
	Print "<th>high:</th> <td>".$row['invention_title'] . "</td> "; 
	Print "<th>lower:</th> <td>".$row['invention-title'] . " </td></tr>"; 
}
Print "</table>";
?>
however, I got 2 error
Notice: Undefined index: country in C:\xampp\htdocs\fak_ict1999\showDB.php on line 11
and line 11 is

Code: Select all

if($_POST['country'] == 'US') { 
Notice: Undefined index: country in C:\xampp\htdocs\fak_ict1999\showDB.php on line 15
and line 15 is

Code: Select all

elseif($_POST['country'] == 'AUD') { 
anyone can solve this?? :help:
thanks

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: filter result by selection

Post by johnj » Mon Apr 08, 2013 7:23 am

This error tells that this particular country is not found in the array created from the table.
http://phillipnb.wordpress.com/2010/11/ ... -and-_get/

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests