无法发布表单,MySQL,PDO / PHP

I'm trying to get two input fields to post to my MySQL database with help from this stackoverflow questions answers. However, I get no input in my db, or any error on my page. What Am I missing? The DB credentials work, as I also have an output of them on my page (not listed here)

I added this to the code from the other thread (as a cfg.php file later included):

<?php
class Database
{

    private $servername = 'mydomain.com';
    private $dbname = 'mydatabase';
    private $username = 'mydatabaseuser';
    private $password = 'mypassword';


    public function dbConnection()
    {


        $this->conn = null;

The code from the thread:

        //check if submit button is clicked
        If (isset($_POST['submit'])) {
            try {
                $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);

                // set the PDO error mode to exception
                $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

                // prepare sql and bind parameters
                $stmt = $conn->prepare("INSERT INTO subscribers (name, email)
    VALUES (:name, :email)");
                $stmt->bindParam(':name', $name);
                $stmt->bindParam(':email', $email);

                $name = $_POST['name'];
                $email = $_POST['email'];
                $stmt->execute();
                echo "New records created successfully";
            } catch (PDOException $e) {
                echo "Error: " . $e->getMessage();
            }
            $conn = null;
        }
else { echo "Not set"; } //Added by suggestion from Funk Forty Niner in this thread

My ending:

    }
}
    ?>

The code for the forms:

<?php include 'cfg.php' ?>





<div class="container">
    <div class="container__item">
        <form class="form"  method="post"> <!-- updated with method as suggested by RamRaider in this thread -->
            <input type="text" name="name" class="form__field" placeholder="Your name" style="margin-bottom:10px;"/><br> <!-- updated from name-type to text-type as suggested by Funk Forty Niner and RamRaider in this thread -->
            <input type="email" name="email" class="form__field" placeholder="Your E-Mail Address" />
            <button type="submit" name="submit" class="btn btn--primary btn--inside uppercase">Send</button>
        </form>
    </div>

</div>
<form class="form">

By default this will use GET as the method

Change to

<form class="form" method='post'>

and, compliments to @Funk Forty Niner for being more diligent and pointing out the mistook with one of the form input elements

<input type="name" ...

should most likely be

<input type="text" ...

EDIT

Following on from previous advice regarding form element types and having read your comments I hope the following might be of help.

Whatever you have in that Database class seems to bring nothing to the party - it is not used in your code when you are actually attempting the insert

For the connection script db.php I suggest saving in the inc folder - store all the other classes and scripts that get re-used in the same location.

example directory structure

Directory of C:\wwwroot\public\html

20/01/2018  18:08    <DIR>          .
20/01/2018  18:08    <DIR>          ..
20/01/2018  18:07    <DIR>          assets
20/01/2018  18:08    <DIR>          content
20/01/2018  18:07    <DIR>          css
20/01/2018  18:07    <DIR>          images
20/01/2018  18:07    <DIR>          inc
20/01/2018  18:07    <DIR>          scripts

So, when you need to include files ( such as your db connection script ) use set_include_path like this before using include or require

set_include_path 'C:\wwwroot\public\html\inc';
include 'db.php';
/*etc*/

-

<?php

    $verbose=false;

    try{

        /*

            database connection script
            --------------------------
            db.php

        */

        $dbuser='root';
        $dbpwd='p4$$w0rD';
        $dbhost='localhost';
        $dbname='geronimo';


        /* optional attribibutes for the connection */
        $options=array( 
            PDO::ATTR_CURSOR                    =>  PDO::CURSOR_SCROLL,
            PDO::ATTR_PERSISTENT                =>  false,
            PDO::MYSQL_ATTR_USE_BUFFERED_QUERY  =>  true,
            PDO::ATTR_EMULATE_PREPARES          =>  false,
            PDO::MYSQL_ATTR_INIT_COMMAND        =>  "SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci', @@sql_mode = STRICT_ALL_TABLES, @@foreign_key_checks = 1"
        );
        $dsn='mysql:host='.$dbhost.';port='.$dbport.';dbname='.$dbname.';charset=utf-8';


        $conn=new PDO( $dsn, $dbuser, $dbpwd, $options );

    }catch( PDOException $e ){
        exit( $verbose ? $e->getTraceAsString() : 'Database connection error' );
    }

?>

And the code to process the form submission

<?php
    if( isset( $_POST['submit'], $_POST['name'], $_POST['email'] ) ) {
        try{
            /*

                Include the database connection. The path used to this
                needs careful attention

            */
            include 'db.php';

            $name=filter_input( INPUT_POST, 'name', FILTER_SANITIZE_STRING );
            $email=filter_input( INPUT_POST, 'email', FILTER_SANITIZE_EMAIL );


            $sql='insert into `subscribers` (`name`, `email`) values ( :name, :email )';
            $stmt=$conn->prepare( $sql );

            if( $stmt ){

                $stmt->bindParam(':name', $name );
                $stmt->bindParam(':email', $email );

                $result=$stmt->execute();
                echo $result ? 'ok' : 'fu manchu say ver bad foo';

            } else {
                throw new Exception('Failed to prepare sql query');
            }
        }catch( Exception $e ){
            echo $e->getMessage();
        }
    }
?>

I ended up scrapping it all instead and using the following instead from here as I'm not that well versed with this yet. In the end, I couldn't even figure out how to use variables for the credidentials and storing them somewhere else for re-usage:

cfg.php:

<?php
// Insert data into mysql database called "subscribers" using PDO

if(isset($_POST['submit']))
{
try {
$pdoConnect = new PDO("mysql:host=mydomain.com;dbname=mydatabase", "myusername", "mypassword");
} catch (PDOException $exc) {
    echo $exc->getMessage();
    exit();
}

    $name = $_POST['name'];
    $email = $_POST['email'];

    $pdoQuery = "INSERT INTO `subscribers`(`name`, `email`) VALUES (:name,:email)";
    $pdoResult = $pdoConnect->prepare($pdoQuery);

    $pdoExec = $pdoResult->execute(array(":name"=>$name,":email"=>$email));

    if($pdoExec)
    {
        echo 'Thank you for your submission!';
    } else {
        echo 'Your sumission failed!';
    }
}
?>

index.php

<div class="container">
    <div class="container__item">
        <form class="form" method="post">
            <input type="text" name="name" class="form__field" required placeholder="Your name" style="margin-bottom:10px;"/><br>
            <input type="email" name="email" class="form__field" required placeholder="Your E-Mail Address" />
            <button type="submit" name="submit" class="btn btn--primary btn--inside uppercase">Send</button>
        </form>
    </div>

</div>