i want to add and display list of medicines we use php oop but it gives me 5 errors even the code works fine.
Notice: Undefined variable: array in D:\wamp\www\poocrud\action.php on line 41
Warning: array_keys() expects parameter 1 to be array, null given in D:\wamp\www\poocrud\action.php on line 9
Warning: implode(): Invalid arguments passed in D:\wamp\www\poocrud\action.php on line
Warning: array_values() expects parameter 1 to be array, null given in D:\wamp\www\poocrud\action.php on line 10
Warning: implode(): Invalid arguments passed in D:\wamp\www\poocrud\action.php on line 10 INSERT INTO medicines() VALUES ('') .
<?php
include "db.php";
class dataoperation extends Database
{
public function insert($table,$fildes){
//"INSERT INTO $table ($m_name,$qty) VALUES ('name','qty')";
$sql = "INSERT INTO ".$table."(".implode(",", array_keys($fildes)).") VALUES
('".implode("','",array_values($fildes))."')";
echo $sql;
$query = mysqli_query($this->con,$sql);
if($query){
return true;
}
}
public function getAll($table){
$sql = "SELECT * FROM ".$table;
$array = array();
$query = mysqli_query($this->con,$sql);
while($row = mysqli_fetch_assoc($query)){
$array[] = $row ;
}
return $array;
}
}
$obj = new dataoperation;
if(isset($_POST["submit"])){
$array = array(
"m_name"=> $_POST["name"],
"qty"=> $_POST["qty"],
);
}
if($obj->insert("medicines",$array)){
header("location:index.php?msg=inserted");
}
?>