I am Using Following Code. But I get this warning message. I don't know why this happens.
mysqli_query() expects at least 2 parameters....
Config:
class org_type
{
private $conn = '';
function __construct()
{
global $con;
$this->conn = $con;
}
public function create(){
$this->create_org_type();
}
$sql = "CREATE TABLE IF NOT EXISTS `org_type`
(
`orgTypeId` int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(orgTypeId),
`orgTypeName` text,
`status` varchar(150),
`create_date` INT(11),
`desp` TEXT DEFAULT ''
)";
mysqli_query($this->conn,$sql);
}*/
public function insert_orgType($orgName,$sts,$editVal){
$now = time();
mysqli_query($this->conn, "INSERT INTO `org_type`(orgTypeName,status,create_date,desp) VALUES ('".$orgName."','".$sts."',".$now.",'".$editVal."')") or die (mysqli_error($this->conn));
$insId = mysqli_insert_id($this->conn);
return $insId;
}
public function select_orgType($id=0){
$str = '';
$arrResult = array();
if($id != 0){
$str .= " AND orgTypeId = $id ";
}
$sql = "SELECT * FROM org_type WHERE 1 $str order by orgTypeId ASC";
$result = $this->conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$arrResult[] = $row;
}
return $arrResult;
}
}
}
mysqli_query()
requires connection variable to be passed. Update your query as following:
mysqli_query($this->conn,"INSERT INTO `org_type`(orgTypeName,status,create_date,desp) VALUES ('".$orgName."','".$sts."',".$now.",'".$editVal."')") or die (mysqli_error());
You need to pass the connection object as a parameter for following function
1st : mysqli_query() expects two parameter
First one is connection object
Second one is query
mysqli_query($this->conn,query);
2nd : mysqli_error()
you need to pass connection object
to mysqli_error($this->conn)
function
3rd : mysqli_insert_id()
you need to pass connection object
to mysqli_insert_id($this->conn)
function
Update 1: you need to include
that connection file
function __construct()
{
global $con;
include('connection.php');
$this->conn = $con;
}