This is my php:
<?php
// branch on the basis of 'calculate' value
include('../php/config.php');
$email = $_POST['email'];
$password = $_POST['pass'];
$result = mysqli_query($db,"select * from Utenti where Email LIKE '$email' AND Password = '$password' ");
if (mysqli_num_rows($result)>0) {
while($row = $result ->fetch_assoc())
{
$GetIdU = $row['ID'];
}
switch ($_POST['action']) {
case "GetAllContact":
$AddC = $db->query("select * from Rubrica where ID_Utente = '$GetIdU'");
if ($rAddC->num_rows > 0) {
$srows = array();
while($row = $AddC ->fetch_assoc())
{
$rows=$row;
}
echo json_encode($rows);
}
break;
case 'LoadAllContact':
echo $_POST['number_1'] . " - " . $_POST['number_2'] . " = " . ($_POST['number_1']-$_POST['number_2']);
break;
case 'GetAllContact':
echo $_POST['number_1'] . " x " . $_POST['number_2'] . " = " . ($_POST['number_1']*$_POST['number_2']);
break;
default:
echo "Azione sconosciuta";
}
}
?>
this is my java code:
// HTTP POST request
private static void sendPost(String post) throws Exception {
String url = "myurl";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
//"sn=C02G8416DRJM&cn=&locale=&caller=&num=12345"
String urlParameters = post;
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
String jsonText = response.toString();
JSONObject json = new JSONObject(jsonText);
System.out.print(json.toString());
//print result
Log.d("Data: ",response.toString());
}
Also I have a html page from that I Checked the CONNECTION to the database. The problem does not seem to be there, also through a simple print from the php, it worked, but querying seems not return any results. I checked the query and there seems no errors, the data are inside the database, where am I doing wrong? Thanks for your time, You are a great comunity!