for study purpose i wrote this PHP script in order to save data into mysql DB,
my final scope is make a post request using Alamofire via an Xcode app i'm developing.
but for trial i'm testing the post request using 'Postman app'
here my php script:
<?php
$host = "127.0.0.1";
$user = "root";
$password = "";
$database = "login_db";
$staff = $_POST['staff_ID'];
$password = $_POST['password'];
$email = $_POST['email'];
$cpt = $_POST['isCPT'];
$name = $_POST['Name'];
$connessione = new mysqli($host,$user,$password,$database);
if ($connessione === false) {
die("errore connessione db " .$connessione->connection_error);
}
$query = "INSERT INTO users (staff_ID , password, email, isCPT, Name ) VALUES(?, ?, ?, ?, ?)";
$stmt = $connessione->prepare($query); //Prepare
$stmt->bind_param("sssss", $staff,$password,$email,$cpt,$name); //Bind
$stmt->execute();//Execute
if($stmt->affected_rows === 0) exit('Nothing was inserted.'); //Check to see if it worked
$stmt->close();
$connessione -> close();
?>
and a screenshot of my post request with Postman:
what is wrong? looks like php not receiving the post value, so each variable are null.
i tried to use isset, but not solving anything...like this for each value, but i end up in error
if (isset($_POST['staff_ID'])){
echo "ok";
}else {
echo "error";
}
error:
<br />
<b>Warning</b>: Undefined array key "staff_ID" in <b>E:\XAMPP\htdocs\test\nxSignUp.php</b> on line <b>8</b><br />
<br />
<b>Warning</b>: Undefined array key "password" in <b>E:\XAMPP\htdocs\test\nxSignUp.php</b> on line <b>9</b><br />
<br />
<b>Warning</b>: Undefined array key "email" in <b>E:\XAMPP\htdocs\test\nxSignUp.php</b> on line <b>10</b><br />
<br />
<b>Warning</b>: Undefined array key "isCPT" in <b>E:\XAMPP\htdocs\test\nxSignUp.php</b> on line <b>11</b><br />
<br />
<b>Warning</b>: Undefined array key "Name" in <b>E:\XAMPP\htdocs\test\nxSignUp.php</b> on line <b>12</b><br />
<br />
<b>Warning</b>: Undefined variable $mysqli in <b>E:\XAMPP\htdocs\test\nxSignUp.php</b> on line <b>35</b><br />
<br />
<b>Fatal error</b>: Uncaught Error: Call to a member function prepare() on null in E:\XAMPP\htdocs\test\nxSignUp.php:35
Stack trace:
#0 {main}
thrown in <b>E:\XAMPP\htdocs\test\nxSignUp.php</b> on line <b>35</b><br />
– Damiano Miazzi May 30 '21 at 11:08