0

i'm a beginner in PHP and i'm study the POST request

i wrote this simple code

<?php

$host = "127.0.0.1";
$user = "root";
$password = "";
$database = "login_db";

$connessione = new mysqli($host,$user,$password,$database);

if ($connessione === false) {

    die("errore connessione db " .$connessione->connection_error);

}

 if (isset($_POST['staff_ID'])){
        echo "ok";
    }else {
        
        echo "errore";
    }

$connessione -> close();

?>

and i send the post request via url with the following link:

http://localhost/test/nxSignUp.php?method=post&staff_ID=4033

why it give me always errore and not OK? im passing the parameter staff_ID.. what i'm doing wrong?

Damiano Miazzi
  • 1,514
  • 1
  • 16
  • 38
  • 1
    You cannot send POST request like that. The variables appended to a url (referred to as query string) result in a GET request. One way to submit a POST request is to submit a form. You can change the condition from `isset($_POST['staff_id'])` to either `isset($_GET['staff_id'])` or isset($_REQUEST['staff_id']);` – endeavour May 30 '21 at 08:28
  • understood, but also if i send a request using xcode and Alamofire it never endup inside the ok case but always fail. – Damiano Miazzi May 30 '21 at 08:59
  • I use neither, so I cannot guess why. However you can dump the `$_SERVER` superglobal with `var_dump()` or `print_r()`. If the dump is unreadable enclose them with a `pre` tag. The key `REQUEST_METHOD` will show the method used. [$_SERVER doc](https://www.php.net/manual/en/reserved.variables.server.php) – endeavour May 30 '21 at 09:41

0 Answers0