I need help to join two PHP codes

0

I'm starting now. I have two PHP codes. One sends one image and the other some information. Both of an application made in IONIC Would you like to join these two codes so that you only make one insert?

Submit information:

<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE");
include "db.php";
$input = file_get_contents('php://input');
$data = json_decode($input,true);
$message = array();
if($data['action'] == "insert"){
 $motivo = $data['motivo'];
 $horario = $data['horario'];


$q = mysqli_query($con,"INSERT INTO 'imovel' ('motivo', 'horario')
VALUES ('$motivo', '$horario')");

if($q){
 $message['status'] = "success";
 }
 else{
 $message['status'] = "error";
 }
 echo json_encode($message);
}

echo mysqli_error($con);
?>

Upload image:

<?php
	include '../ionx/db.php';
	
    $target_dir = "images/";
	$target_file = $target_dir . basename($_FILES["photo"]["name"]);
	$imagename = basename($_FILES["photo"]["name"]);
	$uploadOk = 1;
	$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
	$check = getimagesize($_FILES["photo"]["tmp_name"]);
	if($check !== false) {
		echo "Arquivo é uma imagem - " . $check["mime"] . ".";
		$uploadOk = 1;
		if (move_uploaded_file($_FILES["photo"]["tmp_name"], $target_file)) {
			
			$q = mysqli_query($con,"INSERT INTO 'imovel' ('imagem') VALUES ('$imagename')");
			
		} else {
			echo "Ocorreu um erro";
		}
	} else {
		echo "Arquivo não é uma imagem";
		$uploadOk = 0;
	}
?>

It's simple, but that's what I was able to make it work haha Would you like to make only one insert using these two codes?

    
asked by anonymous 16.10.2018 / 15:24

0 answers