-1

i am having issues with the query below its showing success with no error but not inserting to the database

here is my code

public function uploadImg($table, $imageurl){
        //path to tore the uploaded images
        $target = "../images/" .basename($_FILES['image']['name']);
        $image = $_FILES['image']['name'];
        //echo $target;
        $sql = "INSERT INTO {$table} ($imageurl) values('$target')";
        $q = $this->DBcon->prepare($sql);
        $q->execute();


        if(move_uploaded_file($_FILES['image']['tmp_name'], $target)){
            echo "uploaded successfully";
        }else{
            echo "error uploading";
        }
    }
}       
Adeojo Emmanuel IMM
  • 2,104
  • 1
  • 19
  • 28

2 Answers2

-2

Try:

$sql = "insert into " . $table . " set " . $imageurl . "=" . $target;

if $tabel and $imageurl exists, a record will be created. And if $target has a string, it will be registered in the field which is represented by $imageurl.

hassan
  • 7,812
  • 2
  • 25
  • 36
-2

fixed

simply change your query from

$sql = "INSERT INTO {$table} ($imageurl) values('$target')";

to

$sql = "INSERT INTO {$table} ('$imageurl') values('$target')"; 
Adeojo Emmanuel IMM
  • 2,104
  • 1
  • 19
  • 28