0
<?php
$db_name = "....";
$mysql_username = "root";
$mysql_password = "";
$server_name = "192.168.56.1";
$conn = mysqli_connect($server_name, $mysql_username, $mysql_password,$db_name);
$response = array();
// check for required fields
$note_title = "test55";
$note_content = "test88";
// mysql inserting a new row
$result = mysql_query("INSERT INTO notes(note_title, note_content) VALUES('$note_title', '$note_content')");
// check if row inserted or not
if ($result) {
    // successfully inserted into database
    $response["success"] = 1;
    $response["message"] = "Product successfully created.";
    // echoing JSON response
    echo json_encode($response);
} else {
    // failed to insert row
    $response["success"] = 0;
    $response["message"] = "Oops! An error occurred.";
    // echoing JSON response
    echo json_encode($response);
}
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);?>

what the problem for this php when you put in android studio the note not save in database.we use phpmyadmin,wampserver and put database in localhost .

RiggsFolly
  • 83,545
  • 20
  • 96
  • 136
  • GOOD Code indentation help understand the flow! You do realise that this code will ALWAYS execute the last `Required field(s) is missing` response and there appears to be no good reason for that code to be there – RiggsFolly Mar 13 '20 at 18:23
  • Did you actually cehck the content of the database? – RiggsFolly Mar 13 '20 at 18:24
  • To get errors out of PHP even in a LIVE environment add these 4 lines to the top of any `MYSQLI_` based script you want to debug `ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);`. This will force any `MYSQLI_` errors to generate an Exception that you can see on the browser as well as normal PHP errors. – RiggsFolly Mar 13 '20 at 18:25
  • While outside the scope of the question, it also appears your code is vulnerable to SQL injection. – esqew Mar 13 '20 at 18:26

0 Answers0