hi everyone.. please my code is having an issue... i made a select query and its displaying the error in the IMAGE attached... the code is also attached... pls what could be the error....

the image ain 't uploading....so below is the error...

( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\wamp\www\testpro\admin\categories.php on line 91
Call Stack
#   Time    Memory  Function    Location
1   0.0025  143568  {main}( )   ..\categories.php:0
2   0.0620  153304  mysql_fetch_array ( )   ..\categories.php:91
Attachments error.jpg 164.39 KB

include '../dbconnect.php';


$cat_name = $_POST['cat_name'];
$cat_desc = $_POST['cat_desc'];
//insert catogory into cat table
$sql = "INSERT INTO categories(cat_name,cat_desc) VALUES('$cat_name','$cat_desc')";
mysqli_query($conn, $sql);


<!DOCTYPE html>
<html lang="en">

    <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">

<title>TEST PRO || CATEGORY</title>
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="../css/testpro.css"/>
<link rel="stylesheet" type="text/css" href="../css/font-awesome.min.css"/>

<body style="overflow-y: visible;">
<div class="container segeo" style="margin-top: 7%;">
        <div class="row center-block well">
            <div class="col-sm-12">
                            <img class="img-circle loginFormPix" src="images/prof_photo.png" height="110" width="110"/>
                            <h2 class="text-center">ADD NEW CATEGORY</h2>
                            <?php if (isset($successREG)) { ?>
                            <div class="col-sm-4 col-sm-offset-4" style="color:#3facff;margin-bottom: 10px;"><?php echo $successREG; ?></div>
                        <?php } ?>
                <form action="#" method="POST">
                    <div class="form-group col-sm-4 col-sm-offset-4 col-xs-8 col-xs-offset-2">
                            <div class="input-group">
                                <span style="background:transparent;color:#333" class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input style="height:40px" type="text" name="cat_name" id="cat_name" placeholder="Category name..." class="form-control inputFlat" required="" />
                            <div class="input-group">
                                <textarea name="cat_desc" id="cat_desc" cols="50" rows="10" placeholder="Describe your category..." class="form-control inputFlat" required=""></textarea>
                            <div class="input-group center-block" style="margin-top: 20px;">
                                <button type="reset" class="btn btn-sm btn-danger" name=""><i class="fa fa-arrow-left"></i>&nbsp;RESET</button>
                                <span><button type="submit" name="cat_submit" id="cat_submit" class="btn btn-sm btn-success pull-right">SUBMIT&nbsp;<i class="fa fa-arrow-right"></i></button></span>
                <div class="col-sm-4 pull-right">
                    //select category names and display

                     $sel = "SELECT cat_name FROM categories ORDER BY cat_id DESC";
                    $selcat = mysqli_query($conn, $sel);
                    if(mysqli_num_rows($selcat) > 0){
                         echo'<h3 class="text-muted text-uppercase text-center text-primary">Categories will be displayed Here...</h3>';
                        echo'<div class="table-responsive">';
                            echo'<table class="table table-striped">';
                               echo '<tr>';
                                    echo'<td style="font-weight: bold;">CATEGORY NAME</td>';
                                    echo'<td style="font-weight: bold;">ACTIONS</td>';
                    while ($catROW = mysql_fetch_array($conn,$selcat)) { 
                                    echo"<td>" .$catROW['cat_name']. "</td>";
    <script src="../js/bootstrap.min.js" type="text/javascript"></script>
    <script src="../js/jquery-2.2.3.js" type="text/javascript"></script>
            var name = $('#cat_name').val();
            var desc = $('#cat_desc').val();
            if($.trim(name && desc) !== ''){
                    url: "categories.php",
                    method: "POST",
error.jpg 164.39 KB error.png 528.16 KB
1 Year
Discussion Span
Last Post by t_thakar

First, this function is depricated - it may be time to learn about MySQLi or other something more modern in the PHP world.

Second, take a look here:

You should be passing ($selcat, FLAG), as $selcat is the "resource" it is expecting (i.e, the result of a query).

For more clarity, look at example #2 in the link above.

Good luck!


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.