Jump to content

[SOLVED] stuck on MySQL query...


ohdang888

Recommended Posts

$mb = mysql_query("SELECT * FROM `message_board`,`message_read` WHERE `message_board.per_code`='$rep_p' AND

(`message_board.state`='$rep_state' OR `message_board.state`='ALL') AND (`message_read.u_id`!='$user' AND `message_read.m_id` != `message_board.id`) ")or die(mysql_error());

 

Unknown column 'message_board.per_code' in 'where clause'

 

but i assure, all of all is spelled correctly, and yes, a column of "per_code" actually exists in the table of "message_board"

 

any ideas?thanks!

Link to comment
https://forums.phpfreaks.com/topic/113327-solved-stuck-on-mysql-query/
Share on other sites

You must of typed something incorrectly. Double check to make sure everything is spelled correctly (your query and your database). You may have made a mistake when creating the table/columns in the database, for example per_code may be typed like par_code something silly like that.

 

Also avoid using SELECT * in your query. List your columns.

CREATE TABLE `message_board` (

  `id` int(11) NOT NULL auto_increment,

  `per_code` int(2) NOT NULL,

  `message` varchar(500) NOT NULL,

  `by` bigint(20) NOT NULL,

  `state` varchar(2) NOT NULL,

  `date` varchar(20) NOT NULL,

  PRIMARY KEY  (`id`),

  UNIQUE KEY `id` (`id`)

)

 

and

 

CREATE TABLE `message_read` (

  `id` int(11) NOT NULL auto_increment,

  `m_id` int(11) NOT NULL,

  `u_id` bigint(20) NOT NULL,

  PRIMARY KEY  (`id`),

  UNIQUE KEY `id` (`id`)

)

 

those are the tables, the SQL just exported... unless i'm blind, which i could be, there's nothing misspelled

Doh! Just noticed whats up, it's to do with the backticks

 

MySQL is trying to find a column called message_board.per_code not the column per_code within the message_board table.

This:

`message_board.per_code`

should be witten as

`message_board`.`per_code`

Only the table/column name needs to be in backticks not the period.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.