如何更改表单以使用URL参数?

时间:2013-02-12 19:51:11

标签: php search

我的表单目前将用户带到usersearch.php,但URL中的数据没有参数。

我怎么能这样做:

usersearch.php

对此?

usersearch.php?username=myAwesomeUsername

这是我的剧本:

<? $user=$_POST["user"]; ?>
<form name="form" action="usersearch.php" method="post">
Username: 
<input type="text" name="user" value="<?echo($user)?>">
<input type="submit">
</form>
<fieldset><!--30-->
<?
$query1="SELECT * FROM users WHERE username LIKE '".mysql_real_escape_string($user)."%' ";
echo("<hr color='red'>Username Results: $user<br><br>");
if(!$user == "")
{
$result1=mysql_query($query1,$con);
while ($row1 = mysql_fetch_object($result1))
{
echo "Username: [".$row1->username."]<br>";
echo "User level: [".$row1->level."]<br>";
echo "User status: [".$row1->status."]<br>";
echo "User email: [".$row1->email."]<br>";
echo "User Bio: [".$row1->bio."]<hr>";
}
}else{
Echo "";
}

1 个答案:

答案 0 :(得分:3)

要获取URL上的?username = part,您需要将表单方法更改为GET:

<form name="form" action="usersearch.php" method="get">