php一个表单get过来时有值,post就获取不到值了
html
<form action="results.php" method="get"> Choose Search Type:<br /> <select name="searchtype"> <option value="author">Author <option value="title">Title <option value="isbn">ISBN </select> <br /> Enter Search Term:<br /> <input name="searchterm" type="text" size="40"> <br /> <input type="submit" name="submit" value="Search"> </form>
<?php // create short variable names @$searchtype=$_GET['searchtype']; @$searchterm=trim($_GET['searchterm']); if (!$searchtype || !$searchterm) { echo 'You have not entered search details. Please go back and try again.'; exit; } if (!get_magic_quotes_gpc()){ $searchtype = addslashes($searchtype); $searchterm = addslashes($searchterm); } @ $db = new mysqli('localhost', 'root', 'lzy', 'books'); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; exit; } $query = "select * from books where ".$searchtype." like '%".$searchterm."%'"; $result = $db->query($query); $num_results = $result->num_rows; echo "<p>Number of books found: ".$num_results."</p>"; for ($i=0; $i <$num_results; $i++) { $row = $result->fetch_assoc(); echo "<p><strong>".($i+1).". Title: "; echo htmlspecialchars(stripslashes($row['title'])); echo "</strong><br />Author: "; echo stripslashes($row['author']); echo "<br />ISBN: "; echo stripslashes($row['isbn']); echo "<br />Price: "; echo stripslashes($row['price']); echo "</p>"; } $result->free(); $db->close(); ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
你调试下看看变量里面有没有呢。
楼主注意:
get_magic_quotes_gpc在新版php中已经废弃了。
我method="post"时用的就是$_post,取不到
<form action="results.php" method="get">
method="get" 这里写 get 就用 get 接收值
method="post" 这里写 post就用 post接收值
不不,我这是写的get的代码,我写成post的时候$_post取值也是取不到
取值也要用$_POST来取