I’m trying to upload pictures to a database. I can display pictures but can’t upload them. Meaning I’ve put the database information right. There are no errors that I get so I’ve no idea what I’m doing wrong. Is anyone willing to help me out on this as I’m not really good with programming and my friend helped me with this.
Can anyone maybe tell me why I’m not seeing error and if possible what the error could be that would be really cool
Here is the code:
$conn = new PDO("mysql:host=$db_server;dbname=$db_database", $db_username, $db_password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (isset($_POST['submit']))
{
$tipe_file1 = $_FILES['image1']['type'];
$tipe_file2 = $_FILES['image2']['type'];
$tipe_file3 = $_FILES['image3']['type'];
$tipe_file4 = $_FILES['image4']['type'];
$prijs = $_POST['prijs'];
$naam = $_POST['fname'];
$beschrijving = $_POST['desc'];
$maat1 = $_POST['maat1'];
$maat2 = $_POST['maat2'];
$maat3 = $_POST['maat3'];
$maat4 = $_POST['maat4'];
if ($tipe_file1 == "image/jpeg" || $tipe_file1 == "image/jpg"){
$aMyUploads = array();
foreach ($_FILES as $aFile) {
if(0 === $aFile['error']){
$newLocation = ''.$aFile['name'];
if(0 === $aFile['error'] && (false !== move_uploaded_file($aFile['tmp_name'], $newLocation))){
$aMyUploads[] = $newLocation;
} else {
$aMyUploads[] = '';
}
}
}
$stmt = $conn->prepare("INSERT INTO `producten` (naam, beschrijving, prijs, maat1, maat2, maat3, maat4, image1, image2, image3, image4) VALUES
(:naam, :beschrijving, :prijs, :maat1, :maat2, :maat3, :maat4, :image1, :image2, :image3, :image4)");
$stmt->execute(array(":naam"=>$naam, ":beschrijving"=>$beschrijving, ":prijs"=>$prijs, ":maat1"=>$maat1, ":maat2"=>$maat2, ":maat3"=>$maat3, ":maat4"=>$maat4, ":image1"=>$aMyUploads[0], ":image2"=>$aMyUploads[1], ":image3"=>$aMyUploads[2], ":image4"=>$aMyUploads[3]));
}else{
echo "<script>alert('Failed to add data! Images must be inputed at last one and filetype JPG/JPEG')</script>
<script>setTimeout(\"self.history.back();\",0000);</script>";