kate_rose Posted October 16, 2012 Share Posted October 16, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/ Share on other sites More sharing options...
Pikachu2000 Posted October 16, 2012 Share Posted October 16, 2012 There is no field named "catagory" in the youtube_playlists table. Make sure you spelled everything correctly. Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385563 Share on other sites More sharing options...
JonnoTheDev Posted October 16, 2012 Share Posted October 16, 2012 (edited) "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 October 16, 2012 by neil.johnson Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385567 Share on other sites More sharing options...
kate_rose Posted October 16, 2012 Author Share Posted October 16, 2012 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?? Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385569 Share on other sites More sharing options...
kate_rose Posted October 16, 2012 Author Share Posted October 16, 2012 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" Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385574 Share on other sites More sharing options...
Pikachu2000 Posted October 16, 2012 Share Posted October 16, 2012 You can't possibly have a field named catagory in that table. If you did, you wouldn't be getting that error. Post the output from the query "SHOW CREATE TABLE youtube_playlists" You can't paste an image; you'd need to attach it . . . Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385576 Share on other sites More sharing options...
mikosiko Posted October 16, 2012 Share Posted October 16, 2012 (edited) 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 October 16, 2012 by mikosiko Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385578 Share on other sites More sharing options...
kate_rose Posted October 16, 2012 Author Share Posted October 16, 2012 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???? Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385580 Share on other sites More sharing options...
Pikachu2000 Posted October 16, 2012 Share Posted October 16, 2012 . . . Post the output from the query "SHOW CREATE TABLE youtube_playlists" . . . Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385581 Share on other sites More sharing options...
kate_rose Posted October 16, 2012 Author Share Posted October 16, 2012 yes mikosiko the name of the column in the DB is "$catagory" (I will try attaching the image to this post so you can see it) Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385583 Share on other sites More sharing options...
Pikachu2000 Posted October 16, 2012 Share Posted October 16, 2012 (edited) You need to rename the fields without the $ signs. The field is not named catagory, it is named $catagory. There's a huge difference. Edited October 16, 2012 by Pikachu2000 Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385584 Share on other sites More sharing options...
kate_rose Posted October 16, 2012 Author Share Posted October 16, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385589 Share on other sites More sharing options...
kate_rose Posted October 16, 2012 Author Share Posted October 16, 2012 Pika, I think all mysql strings automatically have a $ at the beginning so what do you mean by rename them?? Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385591 Share on other sites More sharing options...
Pikachu2000 Posted October 16, 2012 Share Posted October 16, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385594 Share on other sites More sharing options...
ManiacDan Posted October 16, 2012 Share Posted October 16, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385595 Share on other sites More sharing options...
kate_rose Posted October 16, 2012 Author Share Posted October 16, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385612 Share on other sites More sharing options...
ManiacDan Posted October 16, 2012 Share Posted October 16, 2012 Mysql workbench never does that. If there's a setting that does that, turn it off. Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385613 Share on other sites More sharing options...
kate_rose Posted October 16, 2012 Author Share Posted October 16, 2012 I will see if I can find the setting Dan but after this I doubt I will forget to check. Thanks again, Kate Quote Link to comment https://forums.phpfreaks.com/topic/269538-help-please-error-unknown-column-catagory-in-where-clause/#findComment-1385635 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.