# php/mysql unknown column in field list



## JuanToothTree (Aug 4, 2012)

Unknown column '$Firstname' in 'field list'

here was the code i've done, can someone help me? 

$query = 'INSERT INTO registration_form (`Firstname` ,`MiddleInitial` ,`Lastname` ,`Address`,`ContactNo` ,`Gender` ,`Username` ,`Password`)
VALUES (`$Firstname` ,`$MiddleInitial` ,`$Lastname` ,`$Address`,`$ContactNo` ,`$Gender` ,`$Username` ,`$Password`)';


----------



## wmorri (May 29, 2008)

Hi,

Can you post more code than that and and you give use the entire error message.


----------



## JuanToothTree (Aug 4, 2012)

this was the error message : Unknown column '$Firstname' in 'field list'


here was the whole code 

```
<html>
    <title>Registration</title>
    <head><center><font size="24">REGISTRATION FORM</font></center>
    </head>
    <body>
        <form name="Regform" method="POST" action="Reg.php">
            
            <b> Firstname </b>
            <input type ="text" name="FN"><br>
            <b> Middle Initial </b>
            <input type ="text" name="MI"><br>
            <b> Lastname </b>
            <input type ="text" name="LN"><br>

            
            <b> Address </b>
            <input type ="text" name="Add"><br>
            <b> Contact No. </b>
            <input type ="text" name="CN"><br>
            <b> Gender </b>
            <select name ="gender" style="width: 160px">
                <option value ="male">Male</option>
                <option value ="female">Female</option>
                <option value ="unknown">Unknown</option>
            </select><br>

            
            <b>USERNAME</b>
            <input type ="text" name="UN"><br>
            <b>PASSWORD</b>
            <input type ="password" name="PASS"><br>
            <b> Confirm Password</b>
            <input type ="password" name="CP"><br>


            <input type ="submit" name="Save" value ="Register">
            <input type ="reset" name="Reset">
            <input type ="button" name="Cancel" value ="Back" onclick="window.location.href='Index.php';">
        </form>
    <?php
            if(isset($_POST['Save']))
                {
                 $Firstname = trim($_POST['FN']);
                 $MiddleInitial = trim($_POST['MI']);
                 $Lastname = trim($_POST['LN']);
                 $Address = trim($_POST['Add']);
                 $ContactNo = trim($_POST['CN']);
                 $Gender = trim($_POST['gender']);
                 $Username = trim($_POST['UN']);
                 $Password = trim($_POST['PASS']);
                 $ConfirmPass = trim($_POST['CP']);

            if ($Password != $ConfirmPass)
                    {
                       print "<script type = 'text/javascript'>
                                alert('Your password did not match dude! XD');
                                    </script>";
                     }
                      else
                      {
            
            if ($Firstname == ''|| $MiddleInitial == '' || $Lastname == '' || $Address == '' || $ContactNo == '' || $Gender == '' || $Username == '' || $Password == '' || $ConfirmPass == '')
                      {
                        print "<script type = 'text/javascript'>
                                 alert('Reminder: Please Fill out all the information needed!');
                                    </script>";
                             
                       }
                        else
                        {
                    $Connection = mysql_connect('localhost','root','') or die(mysql_error());
                    mysql_select_db('registration') or die (mysql_error());
                    $query = 'INSERT INTO registration_form (`Firstname` ,`MiddleInitial` ,`Lastname` ,`Address`,`ContactNo` ,`Gender` ,`Username` ,`Password`)
                        VALUES (`$Firstname` ,`$MiddleInitial` ,`$Lastname` ,`$Address`,`$ContactNo` ,`$Gender` ,`$Username` ,`$Password`)';

                    $Result = mysql_query($query) or die(mysql_error());
                                echo 'Succesful!';
                                echo    "<meta http-equiv=refresh content=1;URL=Reg.php>";
        }
        }
        }
        
            
        ?>
```


----------

