SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    uk colchester
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    insert data help for beginner

    I have a table with 7 rows in it, I have a form which sends the data for these form fields but it gives me an error of:

    Unknown column 'date' in 'field list'

    I have the following code which i am trying to insert the data with

    //insert the data
    if (isset($_POST['date'])) {
    $club = $_POST['club'];
    $type = $_POST['type'];
    $class = $_POST['class'];
    $location = $_POST['location'];
    $results = $_POST['results'];
    $pictures = $_POST['pictures'];
    $date = $_POST['date'];
    $sql = "INSERT INTO joke SET
    date='$date',
    club='$club',
    type='$type',
    class='$class',
    location='$location',
    results='$results',
    pictures='$pictures'";
    if(@mysql_query($sql)) {
    echo '<P> The Fixture Has been added</p>';
    } else {
    echo '<p> error adding Data: ' .
    mysql_error() . '</p>';
    }
    }

    The date field in the database is text not null, wonder if someone can point me in the right direction

    Regards

    Ian

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    DATE is a reserved word, try it in backticks, `date`, or better yet, use a more descriptive column name, like date_added

    also, i advise avoiding mysql-proprietary syntax like INSERT SET -- it won't work if you ever have to port your application to any other database, but if you use standard sql (INSERT VALUES), you won't have to change it

    use this instead --

    INSERT INTO joke
    ( `date`,club,type,class,location,results,pictures )
    VALUES
    ( '$date','$club','$type','$class','$location','$results','$pictures')
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    uk colchester
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thankyou so much for your advice, I am learning this from a book so getting advice on these forums helps me sort out my errors.

    Thanks again Ian


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •