PHP出现这个问题,求解!Call to a member function fetch_assoc() on a non-object i

<?php
$xh=$_GET['xh'];
$db=new mysqli("localhost","root","","test");
$q= "select * from stu where xh=$xh";
$r=$db->query($q);
$row=$r->fetch_assoc();
?>
<form action="save.php">
<p>学号:<input type=text name=xh value=<?php echo $row['xh'];?> size=20 readonly> </p>
<p>姓名:<input type=text name=xm value=<?php echo $row['xm'];?> size=20> </p>
<p>性别:<input type=radio value=0 <?php if($row['xb']==0) echo "checked";?> name=xb >male<input type=radio value=1 <?php if($row['xb']==1) echo "checked";?> name=xb >female</p>
<p><input type=submit value="提交" name=tj>
<input type=reset value="重置" name=cz></p>
</form>
<?
$r->free();
$db->close();
?>

if(isset($_GET['xh'])){
    $xh=$_GET['xh'];
    $db=new mysqli("localhost","root","","test");
    $q= "select * from stu where xh=".intval($xh);
    $r=$db->query($q);
    $row=$r->fetch_assoc();
}

追问

谢谢你,这个问题是解决了,但是下面的表单出现问题了,你可以再帮我看看吗,就是value=这里出现问题了

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网