duan205571 2013-07-17 12:11
浏览 110

如何在url中添加搜索值

Can someone help me insert the text user enters into the search form into the url?

For example: if user searches "the walking deads" it would look like this:

www.domain.com/search.php?=the+walking+deads/

This is my code:

    <?php
function connect($host,$username,$database,$password){
 $to_connect = mysql_connect($host,$username,$password) or die ("UNFinded ".$username. " DB !");
 $db = mysql_select_db($database, $to_connect) or die (mysql_error());
 return $db;
}
connect("localhost","idevice2_ariel","idevice2_ariel","ariel123456");

if (!isset($_POST['submit_form'])) {
    echo '<form name="search_form1" id="form" method="POST" action="search.php">
<input type="text" style="width: 300px; display: block; margin: 0 auto; height: 36px; text-align: center; font-size: 16px;" name="search_name" placeholder="חפש סרט או סדרה..." />
<input type="submit" value="Submit" name="submit_form" />
</form>';
} else {
       $search_name = $_POST['search_name'];
       $query = mysql_query("SELECT * FROM `members` WHERE (`moviename` like '%".$search_name."%')");
       $count = mysql_num_rows($query);
       while($row = mysql_fetch_array($query)) {
       $fname = $row['moviename'];
       $lname = $row['links'];
print '<a href="'.$row['links'].'">'.$row['moviename'].'</a><br />';
}
}
mysql_close($to_connect);
?>
<html>
<head>
<style type="text/css">
a {
padding:25px 560px;
    color: red;
}
</style>
</head>
<body>

</body>

</html>

$search_name is what user enters in the search input. now the url still only has the search file name.. Thanks!

  • 写回答

1条回答 默认 最新

  • dongqin6926 2013-07-17 15:22
    关注

    Your form is sending datas via POST method ( <form ... method="POST">). If you want the data into your url, you should set method="GET". With this method, you will have to change your data retrieving from "$_POST['search_name'];" to "$_GET['search_name'];"

    But WARNING, your data are raw, you have to validate, sanitize and escape them, otherwise anybody could try sql injection with this code.

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改