why image is not uploadded to DB?


#1

[php]f(isset($_POST[‘submit’])){

 $stmt = $connection->prepare("INSERT INTO advert (title, email, phone, place, options, name,  lastname,  message, kod ,  image, rodzaj, cena,  ip) VALUES (?, ?, ?,?, ?, ?,?, ?, ?,?, ?, ?,?)");

$stmt->bind_param(“sssssssssbsss”, $title, $email, $phone, $place, $options, $name, $lastname, $message, $randomString, $file, $rodzaj, $cena, $ip);

$title=filter_var($_POST[‘title’], FILTER_SANITIZE_STRING);
$email=filter_var($_POST[‘email’], FILTER_SANITIZE_STRING);
$phone=filter_var($_POST[‘phone’], FILTER_SANITIZE_STRING);
$place=filter_var($_POST[‘place’], FILTER_SANITIZE_STRING);
$options=filter_var($_POST[‘options’], FILTER_SANITIZE_STRING);
$name=filter_var($_POST[‘name’], FILTER_SANITIZE_STRING);
$lastname=filter_var($_POST[‘lastname’], FILTER_SANITIZE_STRING);
$message=filter_var($_POST[‘message’], FILTER_SANITIZE_STRING);
$rodzaj=filter_var($_POST[‘optradio’], FILTER_SANITIZE_STRING);
$cena=filter_var($_POST[‘cena’], FILTER_SANITIZE_STRING);
$length = 10;

$randomString = substr(str_shuffle(“0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”), 0, $length);
$ip=$_SERVER[“REMOTE_ADDR”];
$file = addslashes(file_get_contents($_FILES[“image”][“tmp_name”]));

$stmt->execute();

$stmt->close();
$connection->close();
}

} ?>[/php]


#2

Need to work on the Data Model a bit. There is too much unrelated data in a single table. And do yourself a favor and skip storing the actual file in the database, and store the path instead.

[You are not doing anything with the file.]


#3

thank you I will keep the path in DB and file in folder . I just find the way how to do this .


#4

Hi,
Theoretically:
Figure out in which folder the uploaded file ($upload_file) is stored, see if it is a temporary folder and if not move the file to permanent folder. Then find out the path of that permanent folder and run update on DB…