I'm pretty new to web development, and I'm trying to save a base64 encoded image on my sql database. The sql statement is working fine as I'm able to place user registration data into the database through PHP, but I'm running into trouble using XMLhttprequest to send the image to PHP so that I can use the $_GET method to receive the data. JQuery is strictly forbidden, so I'm stuck pretty bad. The image variable has the data in, and I did check to see that it's saved correctly. This is how I'm sending the XML request:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
alert(this.responseText);
}
}
xhttp.open("POST", "saveimage.php?img="+image, true);
xhttp.send();
The image variable contains the data. This code runs as well, since I placed alerts in between to make sure it does. Onto the saveimage.php file then:
<?php
session_start();
$email = $_SESSION['email'];
$image = $_GET['img'];
$conn = new PDO("mysql:host=localhost; dbname=camagru", "root", "admin");
$conn->setAttribute(PDO::ERRMODE_EXCEPTION);
$sql = $conn->prepare("INSERT INTO `images` (`image`, `email`) VALUES (:image, :email");
$sql->bindParam(':image', $image);
$sql->bindParam(':email', $email);
$sql->execute();
?>
Sadly from here, nothing happens. My database remains empty, no matter what. Am I missing something? It doesn't look like the PHP script is running at all.