May 27, 2013

Error: Unknown column 'Date' in 'field list'

Manju’s Question:

I am working on a blood bank data base but i am repeatedly getting a Error: Unknown column ‘Date’ in ‘field list’.there is no spelling error in either php or mysql so here is my php code

<?php
    $con=mysqli_connect("localhost","root","","bloodbank");
    // Check connection
   if (mysqli_connect_errno())
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }

   $sql="INSERT INTO users       (First,Last,Date,Email,Contact,Bloodgroup,Gender,address,City,username,password)
    VALUES
    ('$_POST[first]','$_POST[last]','$_POST[dob]','$_POST[email]','$_POST[contact]','$_POST[bg]',
'$_POST[sex]','$_POST[address]','$_POST[city]','$_POST[username]','$_POST[password]')";

    if (!mysqli_query($con,$sql))
    {
    die('Error: ' . mysqli_error($con));
    }
    echo "1 record added";

    mysqli_close($con);
    ?></code>

Basic explanation would be that Your query does not matches with your table structure

INSERT INTO users(First,Last,Date
                             ^ // Right here you are using it

Check your table structure using tools like phpMyAdmin and if the field does exist, Date is a reserved word so that might be creating the problem.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!