I need help uploading pictures to my database, in Sequel Pro. This is the HTML code in order to run the PHP script once the user has pressed the "Submit" button:
<form action="/Alesh_New_Website/saveImg.php" method="POST" enctype="multipart/form-data">
<input type="file" name="image">
<input type="submit" name="submit" value="Upload">
</form>
This is the PHP code:
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "IMGSTORAGE";
try{
$conn = new PDO("mysql:host=$servername; dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$name = addslashes($_FILES['image']['name']);
$image = addslashes($_FILES['name']['tmp_name']);
$image = file_get_contents($image);
$image = base64_encode($image);
$sql = "INSERT INTO 'STOREDIMG' ('name', 'image') VALUES ('$name, $image')";
$conn->exec($sql);
echo "Image uploaded";
}
catch (PDOException $e){
echo "Connection Failed: " . $e->getMessage();
}
?>
I was watching videos in order to create this PHP statement; I barely know about PHP, but I want to learn it at its fullest. I need a way to make this work, since every time I run it, I get this error:
"Connection Failed: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''STOREDIMG' ('name', 'image') VALUES ('Image_Name.jpg, ')' at line 1"
Is there any way I can fix this or make it work in order to serve the purpose I want? I appreciate your help. Thank you.