So, I am putting a drawing app on my website, but one thing is that no matter what I try, the save info is not inserting into my 'gallery' database. I have all the table data set up right, but when I try to get the insert working, it doesn't.
PHP Code:
function generateRandomString($length = 5){
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
return $randomString;
$randomstring = generateRandomString();
$img = mysql_real_escape_string(stripslashes($_POST['data']));
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = "drawings/".strtolower($session->username)."-".$randomstring.".png";
file_put_contents($file, $data);
mysql_query("INSERT INTO gallery(artist,title,desc,drawing)VALUES('$session->username','$name','$desc','$file')");
Note that the included "session.php" file contains all the database connections. My friend (who made the original script, but it doesn't fit with my database) couldn't seem to help either. Please tell me what I am doing wrong. Thanks!