I have this code here. The connection with the DB is okay, and when the variables’ values are strings, the values are inserted without any problem. However, when I’m using $_POST, the database inserts a new user with empty values and doesn’t take the values I inserted through the request.
note: I’m learning PHP from a few days.
this is the code:
<?php
include "../connect.php";
$username=isset($_POST["username"]) ? $_POST["username"]:'';
$email=isset($_POST['email']) ? $_POST['email']:'' ;
$password=isset($_POST['password']) ? $_POST['password']:'';
$stm=$con->prepare("INSERT INTO `users` (`username`,`email`,`password`) VALUES
(?,?,?)");
$stm->execute(params: array($username,$email,$password));
$count=$stm->rowCount();
if($count>0){
echo json_encode(array('status'=>'sucsses'));
}else{
echo json_encode(array('status'=>'fail'));
}
I use Thunder Client to send a request:
Recognized by PHP Collective
11