Date Not Saving in Mysql from Php Registration Form

前端 未结 4 1422
别跟我提以往
别跟我提以往 2021-01-29 08:46

I am having trouble saving the date of birth in Mysql Db from Php registration form, what am I doing wrong?

  1. Check.php

    $month = $_POST[\'month\'];
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-29 09:21

    As others guys are saying, why not using PDO or MySQLi?

    Your code will be more simple to code, and your code can be maintained over the time with other newer versions of PHP (MySQL FUNCTION ARE DEPRECATED FROM PHP5.5), e.g :

    prepare('INSERT INTO users(FirstName,LastName,Phone,DOB) VALUES (:firstname, :lastname, :phone, :dob)')
        $stmt->execute(array(
            'firstname' => $FirstName,
            'lastname' => $LastName,
            'phone' => $Phone,
            'dob'=> $dob
        ));
    
        echo "Successful Registration!"; 
    
    ?>
    

    I include a solution for simplify DOB using session.

    EDIT (adding how to use pdo_mysql) :

    // $DNS contain host (mysql:host=localhost by default), the database name and MySQL port (port=3606 by default).
    $dns = 'mysql:host=localhost;dbname=beathost_cms;port=3606';
    // $user --> MySQL USER
    $user = 'root';
    // $pass --> MySQL PASSWORD
    $pass = 'root*';
    try {
    
                $pdoconnect = new PDO($dns, $user, $pass);
                $pdoconnect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
    
            } catch (PDOException $e) {
                die ('An error occured with MySQL: ' . $e->getMessage());
            }
    

提交回复
热议问题