stack
stack

Reputation: 67

unknown column error in insert mysql query in php?

Despite reading quite many posts i cannot solve this error- Unknown column 'alt.atheism1111' in 'field list' the fields filename,category may have . in the middle of numbers or words, im using phpmyadmin for database

function insert_rec($cat,$file,$wordid,$synsetid,$seqno)
{
    $cat=mysql_real_escape_string($cat);
    $file=mysql_real_escape_string($file);
    $wordid=mysql_real_escape_string($wordid);
    $synsetid=mysql_real_escape_string($synsetid);
    $seqno=mysql_real_escape_string($seqno);
    echo $cat."  ". $file ."  ". $wordid."  " . $synsetid."  " . $seqno;
     $sql="INSERT  INTO `wordnet50`.`table`  (`category`,`filename`,`wordid`,`synsetid`,`seqno`) VALUES (`" . $cat . "`,`" . $file. "`,`" . $wordid. " `,`" . $synsetid . "`,`" .$seqno . "`)";
     $result=mysql_query($sql);

    if(!$result)
    {
    die(mysql_error()); 
    }
}

Upvotes: 0

Views: 1521

Answers (4)

Arfeen
Arfeen

Reputation: 2623

$sql="INSERT  INTO `wordnet50`.`table`  (`category`,`filename`,`wordid`,`synsetid`,`seqno`) VALUES (`" . $cat . "`,`" . $file. "`,`" . $wordid. " `,`" . $synsetid . "`,`" .$seqno . "`)";

You need to remove "`" from the above query in the values only and replace it with " ' " (single quote)

Upvotes: 2

Aditya Kumar
Aditya Kumar

Reputation: 793

if u can post ur db schema than it will be easy to check, as of now it look like u have a field as alt.atheism1111 which can be the show stopper

or use this:

 $sql = "INSERT INTO `wordnet50`.`table` (`category`,`filename`,`wordid`,`synsetid`,`seqno`)
    VALUES ('$cat', '$file', '$wordid', '$synsetid', '$seqno')";

Upvotes: -2

John Woo
John Woo

Reputation: 263723

It should be wrapped with single quotes not with back tick.

$sql = "INSERT  INTO `wordnet50`.`table`  (`category`,`filename`,`wordid`,`synsetid`,`seqno`) VALUES ('" . $cat . "','" . $file. "','" . $wordid. "','" . $synsetid . "','" .$seqno . "')";

BackTick escapes MYSQL Reserved WORDS.

Upvotes: 0

flowfree
flowfree

Reputation: 16462

Use backticks for field names and single quotes for the values.

$sql = "INSERT INTO `wordnet50`.`table` (`category`,`filename`,`wordid`,`synsetid`,`seqno`)
        VALUES ('$cat', '$file', '$wordid', '$synsetid', '$seqno')";

Upvotes: 1

Related Questions