<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>User-Jurisdiction</title>
</head>
<body>
<form action="?action=ask" method="post">
Key:<input type="text" name="key_in" />
<input type="submit" value="Go" />
</form>
<?php
if($_GET['action']=='ask')
{
$key_in=$_POST['key'];
$conn=mysql_connect("216.83.61.xxx","xxx","xxx");
mysql_select_db("lianmeng7",$conn);
mysql_query("set names gb2312");
$query="select * from hongling_user where key='$key'";
$result=mysql_query($query);
$rows=mysql_num_rows(mysql_query($query));
if ($rows==0){
echo "[nothing]";
exit;
}
while ($row=mysql_fetch_array($result))
{
echo "Now=[",date("Y-m-d"),"] ";
echo "BeginTime=[",$row[begintime],"] ";
echo "AllTime=[",$row[alltime],"] ";
echo "Jurisdiction=[",$row[jurisdiction],"] "."<br>";
}
mysql_close($conn);
}
?>
</body>
</html>上面代码的功能是查询数据库中的某项值,如果存在,就返回其它对应的内容,如果不存在就返回nothing。
我输入了一个数据库已存在的值,但始终是返回nothing,我确定数据库里存在所要查询的值,请问上面代码错在哪里?
$key_in=$_POST['key'];
//这一行,html代码中文本输入框的name不是key_in吗,
$key_in=$_POST['key_in'];//改成这样呢
表单中也只有 key_in,而无 key
$sql = 'SELECT * FROM `hongling_user` WHERE `key`=\'12321-123145-45454\'';
特别注意:在=号前面和后面都必须有个空格,否则就会报错,哎,PHP的格式居然如此....
<form action="?action=ask" method="post">
//下面用get方法?