I'm getting back into programming once again and I'm currently stuck as I'm unable to upload an image to my database. I was reading some codes and answers last night and I'm still stuck here..It returns "New record created successfully" but nothing is being stored on my database. Hoping someone will help me to make a workaround on this one :) Thanks!
<form method="post" action="" enctype="multipart/form-data">
Upload File:
<input type="file" name="upload" /><br>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
<?php
$servername ="localhost";
$username = "root";
$password = "";
$dbname = "produ_db";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if(isset($_POST['submit']) ){
$filename = $conn->real_escape_string($_FILES['upload']['name']);
$filedata= $conn->real_escape_string(file_get_contents($_FILES['upload']['tmp_name']));
if ($_FILES['upload']['name'] == 0 ){
echo "<br><br> New record created successfully";
}
else {
/*where acc_cap is the image caption && acc_img is a blob type to store images*/
$query = "INSERT INTO accessories(`acc_cap`,`acc_img`) VALUES ('$filename','$filedata')" ;
if ($conn->query($query) === TRUE) {
echo "<br><br> New record created successfully";
} else {
echo "Error:<br>" . $conn->error;
}
}
$conn->close();
}
?>
Aucun commentaire:
Enregistrer un commentaire