当前位置: 代码迷 >> PHP >> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result reso,该怎么解决
  详细解决方案

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result reso,该怎么解决

热度:390   发布时间:2016-04-28 19:11:31.0
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result reso
为什么查询的内容没有显示
<div class="right_container">
<div class="key_words">
<div class="search">
<form method="POST" action="" name="myform">
查询条件: <select name="sel_tj" id="sel_tj">
<option>用户名</option>
</select>
关键字
<input type="text" name="search_key" id="search_key"/>
<input type="hidden" name="_act" value="search" />
<input type="submit" name="submit" value="提交" onClick="return check();">
</form>
</div>
</div>
<?php
if(isset($_POST[search_key])){
$tj=$_POST[sel_tj];
$key=$_POST[search_key];
$sql=mysql_query("select * from bg_user where $tj='$key'",$_link);
$result=mysql_fetch_array($sql); 
if($result!=false){
echo "<script>alert('对不起,该用户不存在!');</script>";
}else{
do{
?>
<table border="1" bordercolor="#ccc" width="600" height="400" align="center" cellpadding="0" cellspacing="0">
<tr width="600" height="40"><td colspan="4" bgcolor="#ccc">用户管理</td></tr>
<tr width="600" height="40">
<td width="100">姓名:</td>
<td><?php echo $result[username];?></td>
<td width="100">性别:</td>
<td><?=$result['sex']?></td>
</tr>
<tr width="600" height="40">
<td width="100">邮箱:</td>
<td><?php echo $result['email'];?></td>
<td width="100">QQ:</td>
<td><?=$result['QQ']?></td>
</tr>
<tr width="600" height="40">
<td width="100">个人主页:</td>
<td colspan="3"><?=$result['homepage']?></td>
</tr>
<tr width="600" height="40">
<td width="100">IP地址:</td>
<td></td>
<td width="100">生日:</td>
<td><?=$result['birthday']?></td>
</tr>
<tr width="600" height="40">
<td width="120">现住城市:</td>
<td colspan="3"><?=$result['city']?></td>
</tr>
<tr width="600" height="40">
<td width="120">家庭住址:</td>
<td colspan="3"><?=$result['addr']?></td>
</tr>
</table>
<?php
}while($result=mysql_fetch_array($sql));
}
}
?>
</div>
------解决方案--------------------
查询失败了!
$sql=mysql_query("select * from bg_user where $tj='$key'",$_link) or die(mysql_error());
------解决方案--------------------
逻辑写反了,if($result!=false)这个该循环输出内容的,你alert了。
------解决方案--------------------
没有名为“用户名”的列

<select name="sel_tj" id="sel_tj">
<option value='用户名对应的列名'>用户名</option>
</select>
  相关解决方案