I need some help here to put image on an "AD" that user creates. I'm doing it with JSON, Android, PHP and MySql
add_ad.php
<?php
//load and connect to MySQL database stuff
require("config.inc.php");
if (!empty($_POST)) {
//initial query
$query = "INSERT INTO ads ( ad_title, ad_price, ad_category, ad_description, ad_user, ad_contact ) VALUES ( :title, :price, :category, :description, :email, :mobile ) ";
//Update query
$query_params = array(
':title' => $_POST['ad_title'],
':price' => $_POST['ad_price'],
':category' => $_POST['ad_category'],
':description' => $_POST['ad_description'],
':email' => $_POST['ad_user'],
':mobile' => $_POST['ad_contact']
);
//execute query
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
// For testing, you could use a die and message.
//die("Failed to run query: " . $ex->getMessage());
//or just use this use this one:
$response["success"] = 0;
$response["message"] = "Erro base de dados. Impossível adicionar o anúncio.";
die(json_encode($response));
}
$response["success"] = 1;
$response["message"] = "Anúncio criado com sucesso! Aguarde aprovação.";
echo json_encode($response);
} ?>
I don't know how to transform this to receive the image from android and save it on the server/database, PLEASE ALSO tell me the type of the field on database.
This is very important, after that I need to send image from my android to this .php and save it on that user.
Thanks, please be aware that I'm new on android, so be brave :)