Insert user input from textbox to Database (PHP to PHPMYADMIN using mysql)
<p>How do you guys insert user input from textbox(html/php) to database (phpmyadmin) using mysql</p>

<p>I keep getting the error "failed to insert" is there something missing with my code.</p>

<p>I did search online on how to fix it but nothing is working. I think something is missing with my code and I can't pin point it.</p>

<p>all files below are in 1 php file named index.php</p>

<pre><code>&lt;!DOCTYPE html&gt;
 &lt;?php

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'dad_trading';

$dbconn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($db);




if (isset($_POST['submit']))
{
    $Lastname   = $_POST['LastName'];
    $firstname  = $_POST['FirstName'];
    $Middlename = $_POST['MiddleName'];
    $address    = $_POST['Address'];
    $city       = $_POST['City'];
    $zipcode    = $_POST['ZipCode'];
    $email      = $_POST['email'];
    $number     = $_POST['number'];


     $query = ("INSERT INTO customer ([LName], [FName], [MName], [Street], [City], [ZipCode], [Email], [ContactNo]) VALUES ('$Lastname', '$firstname', '$Middlename', '$address', '$city','$zipcode', '$email', '$number')");

if(mysql_query($query))
 {
echo "&lt;script&gt;alert('INSERTED SUCCESSFULLY');&lt;/script&gt;";
}
else
 {
 echo "&lt;script&gt;alert('FAILED TO INSERT');&lt;/script&gt;";
 }

 }
?&gt;

&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset="UTF-8"&gt;
        &lt;title&gt;sample&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;form action="" method = "POST"&gt;

   First name:   
  &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
  Middle Name:
  &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
  Last Name:&lt;br&gt;
  &lt;input name="FirstName" size="15" style="height: 19px;"  type="text" required&gt;
      &amp;nbsp; &amp;nbsp; &amp;nbsp; 
  &lt;input name="MiddleName" size="15" style="height: 19px;"  type="text" required&gt;
      &amp;nbsp; &amp;nbsp; &amp;nbsp; 
  &lt;input name="LastName" size="15" style="height: 19px;"  type="text" required&gt;

  &lt;br&gt;&lt;br&gt;

    Email Address:&lt;br&gt;
  &lt;input name="email"  type="text" required placeholder="Enter A Valid Email Address" style="height: 19px;" size="30"&gt;&lt;br&gt;&lt;br&gt;

  Home Address: &lt;br&gt;
  &lt;input name="Address" type="text" required placeholder="Enter your home Address" style="height: 19px;" size="30" maxlength="30"&gt;&lt;br&gt;&lt;br&gt;

  City:
   &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;
  Zipcode:
   &lt;br&gt;
  &lt;input name="City" size="7" style="height: 19px;"  type="text" required&gt;
    &amp;nbsp; &amp;nbsp; 
    &lt;input name="ZipCode" size="7" style="height: 19px;"  type="text" required&gt;
    &lt;br&gt;&lt;br&gt;

  Telephone/Mobile Number: &lt;br&gt;
  &lt;input name="number" type="text" required id="number" placeholder="Mobile Number" style="height: 19px;"&gt;

&lt;br&gt;
&lt;br&gt;

&lt;button type ="submit" name="submit" value="send to database"&gt; SEND TO DATABASE &lt;/button&gt;
&lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;   
</code></pre>