0

hello i'm following specific php code for login , and i tried to write html code to handle it or to handle the php code with data from users , but the html code doesn't work properly

here is part of the php code that i'm trying to follow :

require_once 'Functions.php';


 $fun = new Functions();



 if ($_SERVER['REQUEST_METHOD'] == 'POST')

   {

   $data = json_decode(file_get_contents("php://input",true));


  if(isset($data -> operation)){


   $operation = $data -> operation;


    if(!empty($operation)){

     if ($operation == 'login') {



    if(isset($data -> user ) && !empty($data -> user) && isset($data -> user -> email) && isset($data -> user -> password)){


    $user = $data -> user;

    $email = $user -> email;

    $password = $user -> password;


        echo $fun -> loginUser($email, $password); 

and my html code :

<form action="" method="post">
<label>email :</label>
<input type="text" name="email"/><br />
 <label>Password :</label>
 <input type="password" name="password"/><br/>
 <input type="submit" value=" Submit "/><br />
 </form>

what im doing wrong with html code ??

fofo
  • 31
  • 1
  • 4
  • Change `$data = json_decode(file_get_contents("php://input",true));` to `$data = json_encode(file_get_contents("php://input",true));` . *Hope it helps* – Prince Adeyemi Sep 09 '17 at 01:32

2 Answers2

0

Nothing is wrong with your html, but it's not sending data as json, so when you do:

$data = json_decode(file_get_contents("php://input",true));

it won't find anything. All of your post data will be in the $_POST global.

dave
  • 62,300
  • 5
  • 72
  • 93
0

There are no problems with your HTML. The problem is with your PHP code.

You should read about $_POST: http://php.net/manual/en/reserved.variables.post.php

I would also suggest you update your code so you get a better idea of what data is actually being provided by your HTML:

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
     var_dump($_POST);
     exit();
}

This will show you exactly what the HTML form is submitting so you can then use it appropriately in PHP.

Mike S
  • 1,636
  • 7
  • 11