In my php script, I am attempting to store a random file name in my MySQL database. However, when I call the variable, nothing is posted to the table. If I change $filetest to a string i.e. 'image12462983764', it will post as expected. Does anyone know why I might have this problem? Please see code below:
<?php
//receive image data, convert from base64 to png, write to server
$rawimagedata = $_POST["varPOST"];
$rawimagedata = str_replace(' ', '+', $rawimagedata);
$decoded = base64_decode($rawimagedata);
$filerand ="image" . rand(0,999) . rand(0,999) . rand(0,999);
$filename =$filerand . ".png";
file_put_contents($filename , $decoded);
//receive device location data
$userlat = $_POST["latitude"];
$userlon = $_POST["longitude"];
echo $userlat;
echo $userlon;
echo $filename;
echo $filerand;
$con=mysqli_connect("localhost","myuser","mypassword","Mydatabase");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$filetest = mysqli_real_escape_string($filerand);
// Perform queries
mysqli_query($con,"INSERT INTO photos (username,lat,lon,photourl)
VALUES ('myusername',$userlat,$userlon,$filetest)");
mysqli_close($con);
?>