PHP/MySQLi Contact Form Not Working with $_POST : <p>So my form seems to work when i put test values in the php file like so:</p>

<pre><code>$name = 'name';
$email = 'test@gmail.com';
$telephone = '123456789';
$message = 'test message';
</code></pre>

<p>However when i replace the test values with the php _POST like so:</p>

<pre><code> $name = $_POST['name']
</code></pre>

<p>everything seems to break and im not sure why.</p>

<p>Got a very simple contact-us form setup in a file contact.html:</p>

<pre><code>&lt;div class="container-fluid"&gt;
    &lt;div class="row"&gt;            
        &lt;div class="col-xs-12 col-sm-9 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2"&gt;
            &lt;div class="form-header"&gt;
                &lt;h8&gt;CONTACT US FORM&lt;/h8&gt;
            &lt;/div&gt;

            &lt;form method="post" action="php/contact.php"&gt;
                &lt;div class="row"&gt;
                    &lt;div class="form-group col-xs-4 col-sm-4 col-md-4 col-lg-4"&gt;
                        &lt;label&gt;Name:&lt;/label&gt;
                        &lt;input type="text" name="name" class="form-control" onchange="capitalise()"&gt;
                    &lt;/div&gt;
                    &lt;div class="form-group col-xs-4 col-sm-4 col-md-4 col-lg-4"&gt;
                        &lt;label&gt;Email Address:&lt;/label&gt;
                        &lt;input type="email" class="form-control" name="email"&gt;
                    &lt;/div&gt;
                    &lt;div class="form-group col-xs-4 col-sm-4 col-md-4 col-lg-4"&gt;
                        &lt;label&gt;Phone Number:&lt;/label&gt;
                        &lt;input type="tel" class="form-control" name="tel"&gt;
                    &lt;/div&gt;

                    &lt;div class="clearfix"&gt;&lt;/div&gt;

                    &lt;div class="form-group col-xs-12 col-sm-12 col-md-12 col-lg-12"&gt;
                        &lt;label&gt;Message:&lt;/label&gt;
                        &lt;textarea class="form-control" rows="6"&gt;&lt;/textarea&gt;
                    &lt;/div&gt;
                    &lt;div class="form-group col-xs-12 col-sm-12 col-md-12 col-lg-12"&gt;
                        &lt;input type="hidden" name="msg" value="contact"&gt;
                        &lt;button type="submit" class="btn btn-default"&gt;Submit&lt;/button&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/form&gt;
        &lt;/div&gt;            
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>Here is the PHP contact form using prepared statements.</p>

<pre><code>&lt;?php

$servername = "*******";
$username = "********";
$password = "********";
$dbname = "*********";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn-&gt;connect_error){
    die("Connection failed: " . $conn-&gt;connect_error);
}

$stmt = $conn -&gt; prepare("INSERT INTO contact (name, email, telephone, message) VALUES (?, ?, ?, ?)");
$stmt-&gt;bind_param("ssss", $name, $email, $telephone, $message);

$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['tel'];
$message = $_POST['msg'];
$stmt-&gt;execute();

echo "New records created successfully";

$stmt-&gt;close();
$conn-&gt;close();

?&gt;
</code></pre>
