PHP insert into MySQL database with REST -


i attempting test inserting in database using restful web service. followed tutorial https://trinitytuts.com/build-first-web-service-php/ whenever post data successful database doesn't display information (ie created entry fields blank). 75% sure advanced rest client don't know whats wrong it. here's code/post command.

post string name=apple&email=banna%40orange.com&pwd=12345&status=ok, picture of how send using advanced rest client.

enter image description here

confi.php file

 <?php  $conn = mysqli_connect("localhost", "root", "", 'tuts_rest');  ?> 

rest of code

        <?php  include_once('confi.php');  if($_server['request_method'] == "post"){ $name = isset($_post['name']) ? mysqli_real_escape_string($_post['name']) : ""; $email = isset($_post['email']) ? mysqli_real_escape_string($_post['email']) : ""; $password = isset($_post['pwd']) ? mysqli_real_escape_string($_post['pwd']) : ""; $status = isset($_post['status']) ? mysqli_real_escape_string($_post['status']) : "";   // insert data data base  $sql = "insert users (id, name, email, password, status) values ('' , '" . $name . "', '" . $email . "', '" . $password . "', '" . $status . "');";  $qur = $conn->query($sql);  if($qur){  $json = array("status" => 1, "msg" => "done user added!");  }else{  $json = array("status" => 0, "msg" => "error adding user!");  } }else{  $json = array("status" => 0, "msg" => "request method not accepted"); }  mysqli_close($conn);  /* output header */  header('content-type: application/json');  echo json_encode($json); ?> 

thank you!

thanks guys! have working though not understand it. problem indeed in advanced rest client application. sending payload application/json , wasn't getting post data when changed content-type application/x-www-form-urlencoded worked. if wants explain why fixed appreciate , i'm sure others well.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -