Php 在web窗体中读取数据库时出错
我试图从数据库中提取与文本框中的数据相匹配的数据,我使用的代码会抛出一个错误 我认为我的SQL查询有问题,但我不确定是什么问题 错误是: 警告:mysql\u fetch\u array()希望参数1是资源,布尔值在第65行的C:\wamp\www\search.php中给出 我的语法:Php 在web窗体中读取数据库时出错,php,html,sql,Php,Html,Sql,我试图从数据库中提取与文本框中的数据相匹配的数据,我使用的代码会抛出一个错误 我认为我的SQL查询有问题,但我不确定是什么问题 错误是: 警告:mysql\u fetch\u array()希望参数1是资源,布尔值在第65行的C:\wamp\www\search.php中给出 我的语法: <html> <head> <link rel="stylesheet" type="text/css" href="style.css"></link&g
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"></link>
</head>
<body>
<form action="" name="formdownload" method="post">
<table>
<tr><td colspan=2><h1>Domestic Flights</h1></td></tr></br>
<td height=50> From:</td><td><input type="From" name="from" size=30/>
<tr><td height=50>To: </td><td><input type="To" name="to" size=30/>
<tr><td><input name="submit" type="submit" value ="Search"></tr></td>
<table border="1" align="center" id="table1" cellpadding="0" cellspacing="0">
<tr>
<th>Flight No</th>
<th>Flight Company</th>
<th>Plane Type</th>
<th>From</th>
<th>To</th>
</tr>
<center>
<?php
$submit = @$_POST['submit'];
$from = @$_POST['from'];
$to = @$_POST['to'];
if($submit)
{
$select=mysql_query("select * from flight where ffrom='$from'and To='$to'");
while($row1=mysql_fetch_array($select))
{
$FlightNo = $row1['FlightNo'];
$FlightCompany=$row1['FlightCompany'];
$PlaneType = $row1['PlaneType'];
$From =$row1['ffrom'];
$To =$row1['To'];
?>
<tr>
<td width="90" align="center">
<?php echo $FlightNo;?>
</td>
<td width="90" align="center">
<?php echo $FlightCompany;?>
</td>
<td width="90" align="center">
<?php echo $PlaneType;?>
</td>
<td width="90" align="center">
<?php echo $From;?>
</td>
<td width="90" align="center">
<?php echo $To;?>
</td>
</tr>
<?php }}?>
</table>
</table>
</form>
</div>
</div>
</div>
</div>
</center>
</body>
</html>
国内航班
发件人:
致:
航班号
飞行公司
平面类型
从…起
到
变量名的行中有一个错误:
$select=mysql_query("select * from logintbl where name='$uname'");
替换为:
$select=mysql_query("select * from logintbl where name='$name'");
编辑:由于您的字段在数据库中被命名为“uname”,下面是正确的代码(添加了mysql\u real\u escape
,安全性更高一些):
REEDIT:您需要第二个参数,但在查询之前没有在PHP中检索到它。您的代码应该是这样的:
<html>
<body>
<form enctype="multipart/form-data" action="" name="formdownload" method="post">
<table border="1" align="center" id="table1" cellpadding="0" cellspacing="0">
<tr>
<th>ID</th>
<th>Name</th>
<th>Password</th>
<th>User Type</th>
</tr>
<center>
<br/><br/><br/>
ID: <input type="text" name="idno" /> <br/><br/>
Name : <input type="text" name="name" /><br/><br/>
Marks : <input type="text" name="marks" /><br/><br/>
<input type="submit" name = "submit" value="submit">
</center>
<?php
$submit = @$_POST['submit'];
$name = @$_POST['name'];
$idno = @$_POST['idno'];
if($submit)
{
$select=mysql_query("select * from logintbl where uname='$name' and Id='$idno'");
while($row1=mysql_fetch_array($select))
{
$id = $row1['ID'];
$name=$row1['uname'];
$pass = $row1['pass'];
$type =$row1['type'];
?>
<tr>
<td width="300" align="center">
<?php echo $id;?>
</td>
<td width="300" align="center">
<?php echo $name;?>
</td>
<td width="300" align="center">
<?php echo $pass;?>
</td>
<td width="300" align="center">
<?php echo $type;?>
</td>
</tr>
<?php }}?>
</table>
</form>
</body>
身份证件
名称
密码
用户类型
ID:
名称:
标记:
注意:不再推荐使用mysql
mysqli
现在是标准。您在哪里设置了$uname变量?我只看到设置了$name…不应该$uname
是$name
?然后停止使用
。这段代码的url是什么,这样我们就可以做一些(注入(mysql测试?:)我已经编辑过了..检查..我现在更新了一个新问题..:(当我在数据库的列中搜索2个变量时,我已经编辑了我的答案,看看它现在是否有效:)我已经解决了…但我现在想用2个字段搜索..我得到了一个错误…我编辑了上面的脚本…错误(警告:mysql\u fetch\u array()希望参数1是resource,布尔值在C:\wamp\www\search.php的第65行给出)哦,等等..我编辑错了..你输入的是我拥有的..它仍然显示错误--警告:mysql_fetch_array()希望参数1是资源,布尔值在C:\wamp\www\search.php的第65行中给出,它可以很好地处理一个..但是当我输入Id='$idno'时,它会给出错误。。
<html>
<body>
<form enctype="multipart/form-data" action="" name="formdownload" method="post">
<table border="1" align="center" id="table1" cellpadding="0" cellspacing="0">
<tr>
<th>ID</th>
<th>Name</th>
<th>Password</th>
<th>User Type</th>
</tr>
<center>
<br/><br/><br/>
ID: <input type="text" name="idno" /> <br/><br/>
Name : <input type="text" name="name" /><br/><br/>
Marks : <input type="text" name="marks" /><br/><br/>
<input type="submit" name = "submit" value="submit">
</center>
<?php
$submit = @$_POST['submit'];
$name = @$_POST['name'];
$idno = @$_POST['idno'];
if($submit)
{
$select=mysql_query("select * from logintbl where uname='$name' and Id='$idno'");
while($row1=mysql_fetch_array($select))
{
$id = $row1['ID'];
$name=$row1['uname'];
$pass = $row1['pass'];
$type =$row1['type'];
?>
<tr>
<td width="300" align="center">
<?php echo $id;?>
</td>
<td width="300" align="center">
<?php echo $name;?>
</td>
<td width="300" align="center">
<?php echo $pass;?>
</td>
<td width="300" align="center">
<?php echo $type;?>
</td>
</tr>
<?php }}?>
</table>
</form>
</body>