$ _POST可以不使用变量

I've been trying to make a simple form but my $_POST doesn't seem to work correctly.

I want to enter the input values into my database, it only work when I enter nothing. As soon as I put text into my input it doesn't work.

<form method="post" action="">
  <label class="title_form" for="last name">Last Name :</label>
  <input type="text" id="last" name="last" required>
  <label for="first name">First Name :</label>
  <input type="text" id="first" name="first" required>
  <input type="submit" id="submit" name="submit" value="S'inscrire">
$(document).ready(function() {
  $("#submit").click(function() {  
    $.post('inscription.php', {
      last: $("#last").val(),
      first: $("#first").val()
    }, function(data) {
      alert(data);
    }, 'text');
  });  
});
$bdd = my database connection;

$first_name = $_POST['first'];
$last_name = $_POST['name'];
if (!empty($first_name) && !empty($last_name)) 
{
  $search = $bdd->prepare("INSERT INTO new_member VALUES (3, '$first_name', '$last_name', 8, 'test', 'test')");
  $search->execute();
}

My INSERT INTO works perfectly when I enter strings directly into my PHP code.

评论