Jump to content

Help Please Error "unknown Column 'catagory' In 'where Clause"


kate_rose

Recommended Posts

Hi,

 

I have read a bunch about this error but I can't figure out what I am doing wrong. I am trying to use a where selector to limit data I pull from my mysql database. The code runs fine before I add the where selector but gives me the "Unknown column 'catagory' in 'where clause'" error as soon as I add it in. The code is

mysql_select_db("NRM_videos") or die(mysql_error()); //use the NRM_videos DB
$data = mysql_query("SELECT * FROM youtube_playlists WHERE catagory='individual'") or die(mysql_error()); //untested code where selector
echo "<p><b><u>NRM Faculty</u></b></p>";
while($info = mysql_fetch_array( $data )) //loops through each instance in the array executing commands inside { } for each instance
{
echo "<b>Name:</b> ".$info['$name'] . " <br/>";
$name = $info['name']; //untested code
$url = $info['playlist_url'];//untested code
echo "<a href=$url>$name</a>"; // untested code
}

 

Usually this error is because someone didn't have required column in their database but I am pretty sure I do. Here is what my DB looks like (hmm . . . I tried to paste in an image of the DB from captured from Mysql workbench but it keeps deleting it in the preview)

 

So I will type it I suppose

$name							 $playlist_url					 $catagory
Dr. Brad Dabbert		 http://www.youtube.com/playlist?list=PLKzzRdXA6QxWsrTsADIAQBAaazxd1vQAo	 individual
Dr. Phil Gipson		 http://www.youtube.com/playlist?list=PLKzzRdXA6QxWkCO46zKStmFcoXw__GZd8 individual 	
Dr. Rob Cox			 http://www.youtube.com/playlist?list=PLKzzRdXA6QxWn2ke9-vicexA_vngeU1z2v individual

well that was a pain - anyone know how to display an image without it getting axed??

Anyway

I know it looks like I don't even need the where selector because my DB is so simple but I am just trying to get the code to work and have not yet entered all the data in the DB.

 

Thanks for your help,

 

Kate

Link to comment
Share on other sites

"Unknown column 'catagory' in 'where clause'"

 

I think you must have a spelling error in your WHERE claus. You have spelled, 'category' with an, 'a' instead of an, 'e'. Check the database field name is spelled correctly as it MUST match the spelling in query.

 

$data = mysql_query("SELECT * FROM youtube_playlists WHERE category='individual'") or die(mysql_error());

Edited by neil.johnson
Link to comment
Share on other sites

Pikachu2000,

 

I understand what the error message means but I do have a column named catagory in my table. That is why I am confused. I tried using "$catagory" instead of "catagory" but that just gave me a syntax error.

 

I even tried subbing in the "name" column name as a test to see if there was something wrong with the "catagory" column name but I get the same error. It seems weird to me since I use the "name" column later in the script and that works fine??

Link to comment
Share on other sites

I do suck at spelling but I just double checked and even if "catagory" is spelled wrong it is spelled wrong both in my DB & in my script.

$data = mysql_query("SELECT * FROM youtube_playlists WHERE catagory='individual'") or die(mysql_error()); //untested code where

[/code}

 

& of course I can't show you my mysql workbench view since I can't paste in an image but trust me it is "$catagory"

Link to comment
Share on other sites

Here is what my DB looks like....

$name $playlist_url $catagory

Dr. Brad Dabbert http://www.youtube.com/playlist?list=PLKzzRdXA6QxWsrTsADIAQBAaazxd1vQAo individual

Dr. Phil Gipson http://www.youtube.com/playlist?list=PLKzzRdXA6QxWkCO46zKStmFcoXw__GZd8 individual

Dr. Rob Cox http://www.youtube.com/playlist?list=PLKzzRdXA6QxWn2ke9-vicexA_vngeU1z2v individual

 

wild guess, but.... In your table your fields are called $name, $playlist_url and $catagory or you just typed it in that way by mistake?

 

it seems to confirm my guess

...but trust me it is "$catagory"...

Edited by mikosiko
Link to comment
Share on other sites

I just tried subbing in name again & got the same error with this code

$data = mysql_query("SELECT * FROM youtube_playlists WHERE name='Dr. Phil Gipson'") or die(mysql_error()); //untested code where selector

 

error reads "Unknown column 'name' in 'where clause'"

 

but when I use the column 'name' in this context the code works fine

while($info = mysql_fetch_array( $data )) //loops through each instance in the array executing commands inside { } for each instance
{
echo "<b>Name:</b> ".$info['$name'] . " <br/>";
$name = $info['name']; //untested code
}

 

so is my problem with the whole DB or something????

Link to comment
Share on other sites

So as you might be able to tell I am pretty new at this so the pause has been me trying to figure out how to implement "SHOW CREATE TABLE"

I ended up using this

 

$showme = mysql_query("SHOW CREATE TABLE youtube_playlists");
echo $showme;

 

It outputs "Resource id #3"

 

Pikachu - I have tried using the $ in my code so it looked like this

$data = mysql_query("SELECT * FROM youtube_playlists WHERE $catagory='individual'") or die(mysql_error()); //untested code where selector

 

but I get this error

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='individual'' at line 1"

 

Also all of the many examples leave off the $. I figured it just designated the mysql datatype as a string.

 

Kate

Link to comment
Share on other sites

No, there is no automatic $ in a mysql query string, doing so would be a really bad idea, as you can see by the problems you're currently having. The $ indicates the start of a php variable, so either the $ would need to be escaped with a backslash, or used only in a single-quoted string every time it appears so it's interpreted as a literal character. You should be able to rename the fields with phpMyAdmin, or whatever DB management application you're using.

Link to comment
Share on other sites

I think all mysql strings automatically have a $ at the beginning so what do you mean by rename them??
That's not even a little bit true.

 

What we're saying is: If you have a column named, literally, `$catagory` that's wrong (two different ways). When you try to do it in PHP, PHP interprets "$catagory" as being an actual PHP variable called $catagory, and tried to rewrite your string.

 

Rename your MySQL columns so there are only letters, numbers, and underscores in them. No dollar signs, no ampersands, no quotes. Just letters and numbers. That way you can be assured that your strings are being built correctly.

 

And fix your spelling now, while your product is young.

 

Link to comment
Share on other sites

This DB was created in mysql workbench and it won't let you use any weird characters like "&" or "$" when you name a column. However it does automatically add a "$" to the begining of any column name where the data it contains will be strings. That was the whole problem. I just had to go back and manually delete the "$" at the begining of each column name.

 

Thank you all for you time and patience.

 

Kate

 

P.S. I will fix my spelling ManiacDan.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.