Aimatos Aimatos - 3 months ago 7
Android Question

php mysql update code

trying to update a database using this code

<?php

/*
* Following code will update a product information
* A product is identified by product id (pid)
*/

// array for JSON response
$response = array();

// check for required fields
if ( isset($_POST['name']) && isset($_POST['username']) && isset($_POST['password']) && isset($_POST['phone']) && isset($_POST['email'])&& isset($_POST['licno'])&& isset($_POST['licdate'])&& isset($_POST['meddate'])&& isset($_POST['flighttime'])&& isset($_POST['income'])&& isset($_POST['costs'])&& isset($_POST['pending'])&& isset($_POST['nextpayment'])&& isset($_POST['total'])) {


$name = $_POST['name'];
$username = $_POST['username'];
$password = $_POST['password'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$licno = $_POST['licno'];
$licdate = $_POST['licdate'];
$meddate = $_POST['meddate'];
$flighttime = $_POST['flighttime'];
$income = $_POST['income'];
$costs = $_POST['costs'];
$pending = $_POST['pending'];
$nextpayment = $_POST['nextpayment'];
$total = $_POST['total'];



define('DB_USER', ""); // db user
define('DB_PASSWORD', ""); // db password (mention your db password here)
define('DB_DATABASE', ""); // database name
define('DB_SERVER', ""); // db server
// array for JSON response



$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE);

$sql = "UPDATE login SET username = '$username', password = '$password', phone = '$phone', email = '$email', license = '$licno', expiration = '$licdate', meddate = '$meddate', flighttime = '$flighttime', income = '$income', costs = '$costs', pending = '$pending', nextpayment = '$nextpayment', total = '$total' WHERE name = $name";
$result = $conn->query($sql) or die (mysqli_connect_error());

// mysql update row with matched pid

// check if row inserted or not
if ($result) {
// successfully updated
$response["success"] = 1;
$response["message"] = "Patient details successfully updated.";

// echoing JSON response
echo json_encode($response);
} else {

}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";

// echoing JSON response
echo json_encode($response);
}
?>


i get no response and the db doesnt update, i dont know whats wrong, im sure im sending all parameters and the name im sending corresponds with the name in the db

in android studio i get this error msg
org.json.JSONException: End of input at character 0 of
i know the mistake is not in android studio, its somewhere in this php cause i get the same eror if i do it with postman

Database parameters are blank in this post but not in the real code , so thats not the problem either

Answer

At the end of the query, change WHERE name = $name"; to WHERE name = '$name'";