Home>

I want to create a new registration function using PHP and Mysql.

Error message

The screen itself can be displayed, but if you check the database, it will be "Empty set" and data will not be sent.
I'd like to point out if there is something strange in the code because I'm a beginner.
Thank you.

Applicable source code
$dsn = 'mysql: dbname = test_login;host = localhost';
$user = 'hoge_user';
$password = 'hogehoge';
$pdo = new PDO ($dsn, $user, $password);
  if (isset ($_ POST ['send'])) {
  echo "Input complete 1";
    $mail = $_POST ['mail'];
    $password = $_POST ['password'];
    $name = $_POST ['name'];
    $sex = $_POST ['sex'];
    $live = $_POST ['live'];
    $introduction = $_POST ['introduction'];
    if (isset ($mail, $password, $name, $sex, $live, $introduction)) {
        echo "Input complete 2";
        $stmt = $pdo->prepare ("INSERT INTO board (mail, password, name, sex, live, introduction)
         VALUES (: mail,: password,: name,: sex,: live,: introduction) ");
        $stmt->bindParam (': mail', $mail, PDO :: PARAM_STR);
        $stmt->bindParam (': password', $password, PDO :: PARAM_STR);
        $stmt->bindParam (': name', $name, PDO :: PARAM_STR);
        $stmt->bindParam (': sex', $sex, PDO :: PARAM_STR);
        $stmt->bindParam (': live', $live, PDO :: PARAM_STR);
        $stmt->bindParam (': introduction', $introduction, PDO :: PARAM_STR);
        $stmt->execute ();
        $pdo->query ($stmt);
        header ("Location:". $_SERVER ['PHP_SELF']);
    } else {
      echo "Some items have not been entered.";
    }
  }
$dbh = null;
?>
 <! DOCTYPE html>
 <html lang = "en">
   <head>
     <meta charset = "utf-8">
     <title></title>
   </head>
   <body>
     <form action = "" method = "post">
       
         <label for = "mail">E-mail:</label>
         <input type = "mail" name = "mail">
       
       
         <label for = "password">Password:</label>
         <input type = "password" name = "password">
       
       
         <label for = "name">Name:</label>
         <input type = "text" name = "name">
       
       
         <label for = "sex">Gender:</label>
         <select type = "text" name = "sex">
           <option value = "male">male</option>
           <option value = "female">female</option>
           <option value = "Other">Other</option>
         </select>
       
       
         <label for = "live">Lives in:</label>
         <input type = "text" name = "live">
       
       
         <label for = "introduction">About me:</label>
         <textarea type = "text" name = "introduction"></textarea>
       
       
         <input type = "submit" name = "send" value = "registration">
       
     </form>
   </body>
 </html>
Code
Supplemental information

I use XAMPP in a local development environment.

  • Answer # 1

    $pdo->query ($stmt);
    ↓↓↓
    $stmt->execute ();

  • Answer # 2


    This type = "submit" name = "send" is a full-width space and name = "send" is not recognized
    Please correct it to a half-width space

    $password = 'hogehoge';
    $password = $_POST ['password'];
    These two should be different variable names