There is a code of crud operations in php using classes. plz help me to correct the error

Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\new\customers.php on line 44

<?php

class Customers
 {

private $name;

private $id;

private $desc;

private $con;

public function __construct($name,$desc)
{

   $this -> name = $name;
   $this-> desc = $desc;
   $this -> con = mysql_connect("localhost", "root", "");
   $this -> db  = mysql_select_db('cust');
}

public function insertData()
{

   $sql = " insert into desc_tbl values  ( 'name','desc')";
   $res = mysql_query($sql);
   mysql_query($res);
echo "<center>Record Inserted</center><br>";

}

public function deleteData($id)
{
    $sql = " delete from desc_tbl where id='$id'";
    $res = mysql_query($sql);
    mysql_query($res);
}

public function fetchData($id)
{
    $sql = " select * from desc_tbl where id='$id'";
    $res = mysql_query($sql);
    mysql_query($res);
}

public function updateData($name, $desc, $id)
{
    $sql = " update desc_tbl set name='$name' , desc='$desc' where id='$id'";
    $res = mysql_query($sql);
    mysql_query($res);
    echo "<center>Record Updated</center><br>";
}



}
?>

test.php

<?php 
require_once("customers.php");
{

$name = "John";
$desc ="Test Desc";

$c = new Customers($name,$desc);
$id = $c->insertData($desc);
echo "New Id is " .$id, '<br>'; 

$c = new Customers($name, $desc);
$id = $c -> deleteData($id);
echo "<center>Record Deleted</center>" .$id, '<br>';

$c = new Customers($name,$desc);
$id = $c -> fetchData($id);
echo "Result is" .$id, '<br>';

$c = new Customers($name,$desc, $id);
$id = $c -> updateData($name,$desc,$id);
echo "Updated Record is" .$id;
}

?>

You have (in every function):

$res = mysql_query($sql);
mysql_query($res);

You need (in every function):

$res = mysql_query($sql);

You try to execute it twice, but the second you use the wrong parameter.

Also take note that it is not recommended to use the mysql_* functions (see the warning in this article, for example, on PHP's official website).

now, plz see this code:

the insert function is working... now to run delete function?

customers.php

<?php 

class Customers
 {

private $name;

private $id;

private $desc;

private $con;

public function __construct($name,$desc)
{

   $this -> name = $name;
   $this-> desc = $desc;
   $this -> con = mysql_connect("localhost", "root", "");
   $this -> db  = mysql_select_db('cust');
}

public function insertData($desc_tbl)
{

   $sql = " insert into $desc_tbl values (NULL,'".$this->name."','".$this->desc."');";
   $res = mysql_query($sql);
   mysql_query($res);
echo "<center>Record Inserted</center><br>";

}

public function deleteData($id)
{
    $sql = " delete from desc_tbl where id='$id'";
    $res = mysql_query($sql);
    mysql_query($res);
echo "<center>Record Deleted</center><br>";
}

public function fetchData($id)
{
    $sql = " select * from desc_tbl where id='$id'";
    $res = mysql_query($sql);
    mysql_query($res[$id]);
echo "<center>Data is</center><br>";   
}

public function updateData($name, $desc, $id)
{
    $sql = " update desc_tbl set name='$name' , desc='$desc' where id='$id'";
    $res = mysql_query($sql);
    mysql_query($res);
echo "<center>Record Updated</center><br>";
}

}
?>

test.php

<?php 
require_once("customers.php");
$name = "John";
$desc ="Test Desc";
$id = "6";
$c =new Customers($name,$desc);

echo $c->insertData("desc_tbl");

//$c =new Customers($name,$desc,$id);

//echo $c->deleteData("desc_tbl");

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.