i am try to upload multiple image into a row in my db. And I get this error
Array to string conversion. thanks
Here is my code.
if (isset($_POST['submit']))
{
//list out your form variables...
$property_name=$_POST['property_name'];
$property_location=$_POST['property_location'];
$property=$_FILES['property']['name'];
$property_price=$_POST['property_price'];
$category_id=$_POST['category_id'];
$status=$_POST['status'];
if (empty($property_name)){
echo "Enter Property Location.";
}elseif (empty($property_location)) {
echo "Description";
# code...
}elseif (empty($property)) {
echo "Select an Image .";
# code...
}elseif (empty($property_price)) {
echo "Enter Price.";
# code...
}
elseif(empty($category_id)){
echo "category_id Feild is required";
}elseif (empty($status)){
echo "Indicate Status of Property";
# code...
}else
$image_name='';
$images_name=array();
for( $x=0; $x < count( $_FILES['property']['tmp_name'] ); $x++ ) {
{
$file_name = $_FILES['property']['name'][$x];
$file_size = $_FILES['property']['size'][$x];
$file_tmp = $_FILES['property']['tmp_name'][$x];
/* Less complicated and more reliable method to find the file extension!! */
$file_ext = strtolower( pathinfo( $file_name, PATHINFO_EXTENSION ) );
$ext_boleh = array( 'jpg', 'jpeg', 'png', 'gif', 'bmp' );
if( in_array( $file_ext, $ext_boleh ) ) {
$uploads_dir = 'uploads/';
$add= move_uploaded_file($file_tmp, $uploads_dir. $file_name);
if($add)$images_name[]=$file_name;
var_dump($file_name);
}
}
// inserting into the database...
$add_pro=$db->insertRow("INSERT INTO property (property_name, property_location, property, property_price, category_id, status)VALUES (?, ?, ?, ?, ?, ?)",
[$property_name, $property_location, $property, $property_price,
$category_id, $status]);
//$arrayName = array(':property_name' =>$property_name ,
// ':property_location'=>$property_location,
// ':property'=>implode(',', ) );
if ( $add_pro== True){
echo "File upload successfully";
}
else{ echo "Upload was Unsuccessful...";}
here is my database class
class Database{
public $isconn;
protected $datab;
public $error;
//connect to db
public function __construct($username="root", $password="", $host= "localhost", $dbname="gold", $options =[]){
$this->isConn= TRUE;
try{
$this->datab=new PDO("mysql:host={$host};dbname={$dbname};charaset=utf8", $username,$password,$options);
$this->datab->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->datab->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
}catch (PDOException $e){
throw new Exception($e->getMessage());
}
}
//disconnect from db
public function Disconnect(){
$this->datab=null;
$this->isConn=false;
}
//get row
public function getRow($query,$params=[]){
try{
$stmt=$this->datab->prepare($query);
$stmt->execute($params);
return $stmt->fetch();
}
catch (PDOException $e){throw new Exception($e->getMessage());
}
}
//get rows
public function getRows($query,$params=[]){
try{
$stmt=$this->datab->prepare($query);
$stmt->execute($params);
return $stmt->fetchAll();
echo $stmt;
}
catch (PDOException $e){
throw new Exception($e->getMessage());
}
}
//insert row
public function insertRow($query,$params=[]){
try{
$stmt=$this->datab->prepare($query);
$stmt->execute($params);
return TRUE;
}catch (PDOException $e){
throw new Exception($e->getMessage());
}
}