I have successfully created a mysql database and trying to fill it with a php file.
the code of the php looks like this:
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$userid = $_POST['userid'];
$time = $_POST['time'];
$button = $_POST['button'];
$weight = $_POST['weight'];
$sex = $_POST['sex'];
$sql = "INSERT INTO beerconsumption (userid, time, button, weight, sex)
VALUES ('userid', 'time', 'button', 'weight', 'sex')";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
if i mannualy call the php file it does make entrys but just 0. if i change the Line
VALUES ('1', 'time', 'button', 'weight', 'sex')";
it puts a one in the first field of the table. but if i use postman or my android app to post different values it still just post 0.
at the moment i just don't get the fault.
Android Script:
public void sendData(){
StringRequest request = new StringRequest(Request.Method.POST, insertUrl, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
}, new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error){
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("verify", "******");
parameters.put("userid",userID);
parameters.put("time",Long.toString(java.lang.System.currentTimeMillis()));
parameters.put("button", Integer.toString(button));
parameters.put("weight",Integer.toString(calc.person.getWeight()));
parameters.put("sex",Integer.toString(calc.person.getSex()));
return parameters;
}
};
requestQueue.add(request);
}
'userid'into the userid field?INSERT INTO beerconsumption (userid, time, button, weight, sex) VALUES ('".$userid."', ''.$time."', '".$button."', '".$weight."', '".$sex."')