user652792
user652792

Reputation:

Unknown column issues in database

please help me with this issue i'm having. I get 'Unknown column 'the_mother_church_id' in 'where clause' . I have check several times the name of the column name in the database, and i'm sure the name is same.

Please where could the problem be.

Thanks

<?php
   $past = mysql_query("SELECT * FROM the_mother_church WHERE the_mother_church_id = '1'") or die(mysql_error()); 
?>

CREATE TABLE

CREATE TABLE IF NOT EXISTS `the_mother_church` (
  ` the_mother_church_id` int(255) NOT NULL,
  `the_mother_church_head` varchar(255) NOT NULL,
  ` the_mother_church_content` varchar(3000) NOT NULL,
  ` the_mother_church_tags` varchar(255) NOT NULL,
  ` the_mother_church_created` datetime NOT NULL,
  ` the_mother_church_image` blob NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Upvotes: 0

Views: 93

Answers (3)

eggyal
eggyal

Reputation: 125865

(Upgrading to an answer)

Your CREATE TABLE statement shows the column was named with a space between the opening quote and the field name: ` the_mother_church_id`. Either:

  1. Use the column name with a space in your query:

    SELECT * FROM the_mother_church WHERE ` the_mother_church_id` = '1'
    
  2. Rename the columns:

    ALTER TABLE `the_mother_church`
      CHANGE ` the_mother_church_id`
              `the_mother_church_id`      int(255)      NOT NULL,
      CHANGE ` the_mother_church_content`
              `the_mother_church_content` varchar(3000) NOT NULL,
      CHANGE ` the_mother_church_tags`
              `the_mother_church_tags`    varchar(255)  NOT NULL,
      CHANGE ` the_mother_church_created`
              `the_mother_church_created` datetime      NOT NULL,
      CHANGE ` the_mother_church_image`
              `the_mother_church_image`   blob          NOT NULL;
    

Upvotes: 2

Your Common Sense
Your Common Sense

Reputation: 157887

There is a space in front of the field name in your table structure.
I'd suggest to re-create a table, removing spaces from the field names.

` the_mother_church_id`
 ^ an excessive space

Upvotes: 0

Igor Timoshenko
Igor Timoshenko

Reputation: 1011

Check the name of the field again. I also advise you to wrap the field name in backticks.

Upvotes: 1

Related Questions