<form name="myform" method="post" action="">
<tr>
<td width="605" height="51" bgcolor="#cc99ff"><div align="center">请输入用户名称
<input name="txt_book" type="text" id="txt_book" size="25">
<input type="submit" name="Submit" value="查询">
</div></td>
</tr>
</form><?php
$link=mysql_connect("localhost","root","") or die("数据库连接失败".mysql_error());
mysql_select_db("mazhiwei",$link);
mysql_query("set names gb2312");
?><?php
$sql=mysql_query("select * from tb_admin");//这两行不要的话就不会报错了
$row=mysql_fetch_row("$sql");//这两行不要的话就不会报错了
if($_POST[Submit]=="查询"){
$txt_book=$_POST[txt_book];
$sql=mysql_query("select * from tb_admin where user like '%".trim($txt_book)."%'");
$row=mysql_fetch_row($sql);
}
?><?php
do{
?>
<tr align="left" bgcolor="#ffffff">
<td width="40" height="20" align="center"><?php echo $row[0]; ?></td>
<td width="40" height="20" align="center"> <?php echo $row[1]; ?></td>
<td width="80" height="20" align="center"><?php echo $row[2]; ?></td>
<td width="200" height="20" align="center"><?php echo $row[3]; ?></td> </tr>
<?php
}while($info=mysql_fetch_object($sql));
?>
首先声明该程序运行正常,只是运行结果里会出现警告:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\php-mysql\mysql_fetch_row.php on line 18我在这段代码里
<?php
$sql=mysql_query("select * from tb_admin");//这两行不要的话就不会报错了
$row=mysql_fetch_row("$sql");//这两行不要的话就不会报错了
if($_POST[Submit]=="查询"){
$txt_book=$_POST[txt_book];
$sql=mysql_query("select * from tb_admin where user like '%".trim($txt_book)."%'");
$row=mysql_fetch_row($sql);
}
?>
将注释的两句删除之后便能正常运行,但是原版的代码有那两句,如果我贸然删除会有怎样的后果?如果可以的话希望高手们能够帮忙解读下整段代码。拜谢了
<tr>
<td width="605" height="51" bgcolor="#cc99ff"><div align="center">请输入用户名称
<input name="txt_book" type="text" id="txt_book" size="25">
<input type="submit" name="Submit" value="查询">
</div></td>
</tr>
</form><?php
$link=mysql_connect("localhost","root","") or die("数据库连接失败".mysql_error());
mysql_select_db("mazhiwei",$link);
mysql_query("set names gb2312");
?><?php
$sql=mysql_query("select * from tb_admin");//这两行不要的话就不会报错了
$row=mysql_fetch_row("$sql");//这两行不要的话就不会报错了
if($_POST[Submit]=="查询"){
$txt_book=$_POST[txt_book];
$sql=mysql_query("select * from tb_admin where user like '%".trim($txt_book)."%'");
$row=mysql_fetch_row($sql);
}
?><?php
do{
?>
<tr align="left" bgcolor="#ffffff">
<td width="40" height="20" align="center"><?php echo $row[0]; ?></td>
<td width="40" height="20" align="center"> <?php echo $row[1]; ?></td>
<td width="80" height="20" align="center"><?php echo $row[2]; ?></td>
<td width="200" height="20" align="center"><?php echo $row[3]; ?></td> </tr>
<?php
}while($info=mysql_fetch_object($sql));
?>
首先声明该程序运行正常,只是运行结果里会出现警告:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\wamp\www\php-mysql\mysql_fetch_row.php on line 18我在这段代码里
<?php
$sql=mysql_query("select * from tb_admin");//这两行不要的话就不会报错了
$row=mysql_fetch_row("$sql");//这两行不要的话就不会报错了
if($_POST[Submit]=="查询"){
$txt_book=$_POST[txt_book];
$sql=mysql_query("select * from tb_admin where user like '%".trim($txt_book)."%'");
$row=mysql_fetch_row($sql);
}
?>
将注释的两句删除之后便能正常运行,但是原版的代码有那两句,如果我贸然删除会有怎样的后果?如果可以的话希望高手们能够帮忙解读下整段代码。拜谢了
do{
?>
<tr align="left" bgcolor="#ffffff">
<td width="40" height="20" align="center"><?php echo $row[0]; ?></td>
<td width="40" height="20" align="center"> <?php echo $row[1]; ?></td>
<td width="80" height="20" align="center"><?php echo $row[2]; ?></td>
<td width="200" height="20" align="center"><?php echo $row[3]; ?></td></tr>
<?php
}while($info=mysql_fetch_object($sql));
mysql_select_db('mazhiwei', $link) or die(mysql_error());//另外,使用$_POST变量的时候,键名要加引号:
//难道"原版"代码中也没有加引号??
if($_POST[Submit]=="查询"){ //改为 if ($_POST['Submit'] == '查询') {
$txt_book=$_POST[txt_book]; //改为 $txt_book = $_POST['txt_book'];
mysql_select_db("mazhiwei",$link); //mazhiwei数据库是否存在,输出错误看看
mysql_select_db('mazhiwei', $link) or die(mysql_error());SQL语句我看了看貌似没有什么问题.因为不了解你的数据库情况 所以有的地方需要你自己测试