Hi I am looking to receive POST data from an Android app and put it into a MYSQL server using PHP to script.
I am getting no results and I have gone through various examples and tutorials.
NEW WORKING PHP SCRIPT
<?php
$needsarray = str_split('$_POST[needs]');
$needs1 = 0;
$needs2 = 0;
$needs3 = 0;
$needs4 = 0;
if ($needsarray[0] =="1"){
$needs1 = 1;
}
if ($needsarray[1] =="1"){
$needs2 = 1;
}
if ($needsarray[2] =="1"){
$needs3 = 1;
}
if ($needsarray[3] =="1"){
$needs4 = 1;
}
$con = mysql_connect("localhost","haitidis_test","S3an");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("haitidis_AppData", $con);
$sql="INSERT INTO Extensive (disaster, people, lat, lng, phone, needs1, needs2, needs3, needs4)
VALUES ('$_POST[disaster]', '$_POST[people]', '$_POST[latitude]', '$_POST[longtitude]', '$_POST[userphone]', $needs1, $needs2, $needs3, $needs4)";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
Nothing really wrong with your code. I tested the Java code in my eclipse and the PHP looks fine. For starters try seeing if your phone code and php code actually talk to each other.
Add a
var_dump($_POST)to the end PHP:Change your code a little bit to this:
Print the results. If your post values are printed, then then there’s nothing wrong on the phone side. Maybe something is wrong in the PHP script although it’s not obvious to me right now. If something went wrong with your connection, the
will be printed.
UPDATE: Since you said, nothing is being inserted into the database. Try doing this:
If the result is false var dump the sql error:
UPDATE:
Are you sure you are using the right password — “S3an” ?
UPDATE:
You should put the following lines of code before closing your connection:
Check your db now if the rows are being inserted.