This is the php script that i am running.Basically what i am trying to do is upload an image and a text onto mysql database using php,mysql and android.
if($_SERVER['REQUEST_METHOD']=='POST'){
$image = $_POST['image'];
$name = $_POST['name'];
require_once('dbConnect.php');
$sql ="SELECT id FROM volleyupload ORDER BY id ASC";
$res = mysqli_query($con,$sql);
$id = 0;
while($row = mysqli_fetch_array($res)){
$id = $row['id'];
}
$path = "uploads/$id.png";
$actualpath = "http://simplifiedcoding.16mb.com/PhotoUploadWithText/$path";
$sql = "INSERT INTO volleyupload (photo,name) VALUES ('$actualpath','$name')";
if(mysqli_query($con,$sql)){
file_put_contents($path,base64_decode($image));
echo "Successfully Uploaded";
}
mysqli_close($con);
}else{
echo "Error";
}
You probably do not want to use INSERT and that without specifying an ID.
I would replace this line:
$sql = "INSERT INTO volleyupload (photo,name) VALUES ('$actualpath','$name')";
with something like:
$sql = "UPDATE volleyupload SET photo = '$actualpath', " .
" name = '$name' WHERE id = $id";
It might need more work for the case where you did not find the id in the first query, because then you might want to INSERT anyway, but don't forget to then also insert a value for ID.