如何解决此视图的\u users.php警告?

j8ag8udp  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(290)

这个php页面是用来查看用户的,我在mysql users表中有一个页面,我还有另一个页面要添加用户,但是view\u users.php不起作用,它给了我“警告:mysql\u error()期望参数1是资源,c:\xampp\htdocs\myproject\view\u users.php第71行中给出null“当我从add\u user.php调用view\u user.php时不起作用2)如果我希望用户只查看不修改数据库,我该怎么办?

<!--for delete Record -->
<?php
    $msg="";
    $opr="";
    if(isset($_GET['opr']))
    $opr=$_GET['opr'];

if(isset($_GET['rs_id']))
    $id=$_GET['rs_id'];

    if($opr=="del")
{
    $del_sql=mysql_query("DELETE FROM users_tbl WHERE u_id=$id");
    if($del_sql)
        $msg="1 Record Deleted... !";
    else
        $msg="Could not Delete :".mysql_error();    

}
    echo $msg;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style_view.css" />
<title>::. Build Bright University .::</title>
</head>

<body>
<div id="style_div" >
<form method="post">
<table width="755">
    <tr>
        <td width="190px" style="font-size:18px; color:#006; text-indent:30px;">View Users</td>
        <td><a href="?tag=susers_entry"><input type="button" title="Add new student" name="butAdd" value="Add New" id="button-search" /></a></td>
        <td><input type="text" name="searchtxt" title="Enter name for search " class="search" autocomplete="off"/></td>
        <td style="float:right"><input type="submit" name="btnsearch" value="Search" id="button-search" title="Search Users" /></td>
    </tr>
</table>
</form>
</div><!--- end of style_div -->
<br />
<div id="content-input">
    <form method="post">
    <table border="1" width="805px" align="center" cellpadding="3" class="mytable" cellspacing="0">
        <tr>
            <th style="text-align: center;">No</th>
            <th style="text-align: center;">Users Name</th>
            <th style="text-align: center;">Password</th>
            <th style="text-align: center;">Type</th>
            <th style="text-align: center;">Note</th>
            <th style="text-align: center;"colspan="2">Operation</th>
        </tr>

         <?php

         $key="";
    if(isset($_POST['searchtxt']))
        $key=$_POST['searchtxt'];

    if($key !="")
        $sql_sel=mysql_query("SElECT * FROM users_tbl WHERE username  like '%$key%' ");
    else
        $sql_sel=mysql_query("SELECT * FROM users_tbl");

    $i=0;

    while($row=mysql_fetch_array($sql_sel)){
    $i++;
    $color=($i%2==0)?"lightblue":"white";
    ?>
      <tr bgcolor="<?php echo $color?>">
            <td><?php echo $i;?></td>
            <td><?php echo $row['username'];?></td>
            <td><?php echo $row['password'];?></td>
            <td><?php echo $row['type'];?></td>
            <td><?php echo $row['note'];?></td>
            <td align="center"><a href="?tag=susers_entry&opr=upd&rs_id=<?php echo $row['u_id'];?>" title="Upate"><img style="-webkit-box-shadow: 0px 0px 0px 0px rgba(50, 50, 50, 0.75);-moz-box-shadow:    0px 0px 0px 0px rgba(50, 50, 50, 0.75);box-shadow:         0px 0px 0px 0px rgba(50, 50, 50, 0.75);" src="picture/update.png" height="20" alt="Update" /></a></td>
            <td align="center"><a href="?tag=view_users&opr=del&rs_id=<?php echo $row['u_id'];?>" title="Delete"><img style="-webkit-box-shadow: 0px 0px 0px 0px rgba(50, 50, 50, 0.75);-moz-box-shadow:    0px 0px 0px 0px rgba(50, 50, 50, 0.75);box-shadow:         0px 0px 0px 0px rgba(50, 50, 50, 0.75);" src="picture/delete.jpg" height="20" alt="Delete" /></a></td>
        </tr>
    <?php   
    }
    ?>
     </table>
   </form>
</div><!-- end of content-input -->
</body>
</html>
vkc1a9a2

vkc1a9a21#

如果没有传递链接标识符,mysql\u error和mysql\u query将采用mysql\u connect的最后一个链接标识符。如果代码从未实际连接到数据库,那么我认为这就是您将得到的错误。确保已连接到mysql服务器并选择了数据库。看到了吗http://php.net/manual/en/function.mysql-connect.php 以及http://php.net/manual/en/function.mysql-select-db.php

相关问题