0

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()); 
    }
}
1
  • 3
    Please stop writing new code with the ancient mysql_* functions. They are no longer maintained and community has begun the deprecation process . Instead you should learn about prepared statements and use either PDO or MySQLi. Commented May 30, 2012 at 12:01

4 Answers 4

2
$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)

Sign up to request clarification or add additional context in comments.

Comments

1

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')";

Comments

0

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.

Comments

-2

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')";

1 Comment

yes ur right,i too figured this out,though its strange because i did try single quotes but it didnt work.the combination of putting the column names within ` and values within single quotes made it work! hope this helps other people with similar problems

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.