如何解决这个view_users.php警告?

时间:2018-06-17 03:06:02

标签: php mysql warnings

这个PHP页面用于查看用户,我在MySQL用户表中,我有另一个页面添加用户,但view_users.php不起作用,它给了我  “警告:mysql_error()期望参数1为资源,在第71行的C:\ xampp \ htdocs \ myProject \ View_Users.php中给出null” 当我从add_user.php调用view_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>

1 个答案:

答案 0 :(得分:-2)

mysql_error和mysql_query假设来自mysql_connect的最后一个链接标识符如果没有传递link_identifier。如果代码从未真正连接到数据库,那么我认为这是您得到的错误。确保已连接到mysql服务器并选择了数据库。请参阅http://php.net/manual/en/function.mysql-connect.phphttp://php.net/manual/en/function.mysql-select-db.php