I have Php script which uploads data to MySql database, I'm sending data from android to this script.
<?php
$mac=null;
$android_id=null;
$con=mysqli_connect("localhost",".....","....","...");
if(isset($_POST["mac"])){
$mac=$_POST["mac"];
}
if(isset($_POST["android_id"])){
$android_id=$_POST["android_id"];
}
if(isset($_POST["latitude"])){
$latitude=$_POST["latitude"];
}
if(isset($_POST["longitude"])){
$longitude=$_POST["longitude"];
}
if(isset($_POST["latitudeDestination"])){
$latitudeDestination=$_POST["latitudeDestination"];
}
if(isset($_POST["longitudeDestination"])){
$longitudeDestination=$_POST["longitudeDestination"];
}
if(isset($_POST["kindOfUser"])){
$kindOfUser=$_POST["kindOfUser"];
}
$query1="select count(*) from marker where mac='$mac' AND android_id='$android_id'";
$result = mysqli_query($con,$query1) or die(mysqli_error($con));
if(mysqli_num_rows($result)==0) {
$query2="INSERT INTO marker (mac,android_id,latitude,longitude,latitudeDestination,longitudeDestination,kindOfUser) VALUES (?,?,?,?,?,?,?)";
$statement=mysqli_prepare($con,$query2) or die(mysqli_error($con));
}
else {
$query3="INSERT INTO marker (mac,android_id,latitude,longitude,latitudeDestination,longitudeDestination,kindOfUser) VALUES (?,?,?,?,?,?,?)";
$statement=mysqli_prepare($con,$query3) or die(mysqli_error($con));
$query4 ="DELETE FROM marker where mac='$mac' AND android_id='$android_id'";
$statement2=mysqli_query($con,$query4) or die(mysqli_error($con));
}
mysqli_stmt_bind_param($statement,"ssdddds",$mac,$android_id,$latitude,$longitude,$latitudeDestination,$longitudeDestination,$kindOfUser);
mysqli_stmt_execute($statement);
$response=array();
$response["success"]=true;
echo json_encode($response);
?>
it returns success=true
, but nothing changes on database.
before I put $mac=null
and $android_id=null
in the starting lines. The error stated that these two variables were undefined. I have debugged android app and data is present, also tried to insert data in mysql database from database interface itself and it worked. So my question is what is the problem in this script?