-2

I need support please, my PHP file can't insert post data from a form to SQL, but when I use constant values instead of $_POST['name'] it works.

<?php
$servername = "localhost";
$username = "hostingo_usrproj";
$password = "basel1990!";
$dbname = "hostingo_project";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 


$name         =$_POST['name'];
$email        =$_POST{'email'];
$usrpassword  =$_POST['usrpassword'];
$mobile       =$_POST['mobile'];



$sql = "INSERT INTO MyGuests (name, email, usrpassword, mobile )
VALUES ('$name', '$email', '$usrpassword', '$mobile')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
 }

$conn->close();
?>
Nick
  • 138,499
  • 22
  • 57
  • 95
Basel
  • 21
  • 1
  • 6

1 Answers1

2
$email        =$_POST{'email'];

as per my thinking here is the issue try this

$email        =$_POST['email'];
Parvej Alam
  • 258
  • 2
  • 8