2011-09-15 229 views
0

我想创建一个搜索功能,为我的汽车的oracle数据库进行分隔。PHP搜索功能

我想知道我在哪里把请求搜索功能放在php脚本的页面上,以便抓取搜索框字段并将它发送到动作php链接来处理数据。

<form name:"search" action="http://www.deakin.edu.au/~sjrem/ssss.php" method="post"> 
<h2> Search for a car of your choice </h2> 

<p> 
<table border="0"> 
<tr> 
<td><input type="text" name="search" /> </td> 
</tr> 

</table>     <p> 
<input type="submit" value="Search" /> 
</FORM> 

回答

0

首先,为什么你的input元素在表中?使用CSS来定位它们。

其次,在http://www.deakin.edu.au/~sjrem/ssss.php,你必须确定表单是否已经提交:

if(isset($_GET["search"])) 
{ 
    //Fire up the connection and go to town! 
} 
else 
{ 
    //Do something else. Or not. Whatever floats your boat. 
} 
2

首先,你要修复您的窗体名称styntax:

<form name:"search" 

<form name="search" 

将此字段添加到您的表单中:

<input type="hidden" name="action" value="search" /> 

在你的PHP:

if ($_POST['action'] == 'search'){ 
    search(); 
} 

function search(){ 
    $keyword = $_POST['search']; 
    // run your code 
}