eldan88 Posted February 21, 2013 Share Posted February 21, 2013 Hey, I have a table called store names that i am trying to do a mysql_fetch_array on. When i pass an ID in to the where clause, it does the mysql_fetch_array. However when I pass in the second coloumn the store_name it gives me an error saying that there is an unkown coloumn in the where clause? Below is the code I am using. $store_name = store1; function get_store_information($store_name) { $query = "SELECT * FROM store_names "; $query .= "WHERE store_name = {$store_name} "; $result = mysql_query($query); confirm_query($result); if($return_array = mysql_fetch_array($result)) { return $return_array; }else { echo "There was an issue reading the store name table"; } } $store_array = get_store_information($store_name); echo $store_array['username']; Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 22, 2013 Share Posted February 22, 2013 (edited) Strike that, read too fast. Attempt 2: You're sending MySQL a string. Strings need to be quoted. It thinks your variable's value is a column name. Edited February 22, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
eldan88 Posted February 22, 2013 Author Share Posted February 22, 2013 Jessica, I apologize I forgot to enter the quotes on store name, when tryping the post. The store name is a $_GET value that gets passed in the function. But everytime it runs the query it says it can't find that specific store name in the "store_name" coloumn. Strike that, read too fast. Attempt 2: You're sending MySQL a string. Strings need to be quoted. It thinks your variable's value is a column name. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 22, 2013 Share Posted February 22, 2013 (edited) What EXACTLY is the error you get? Read the post in my signature about debugging SQL and follow those steps. Give us the error message and the final query. Edited February 22, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
exeTrix Posted February 22, 2013 Share Posted February 22, 2013 (edited) @eldan88 because you're doing a string comparison make sure there aren't any characters in the name which could be getting encoded when sent via GET. Edited February 22, 2013 by exeTrix Quote Link to comment Share on other sites More sharing options...
DavidAM Posted February 22, 2013 Share Posted February 22, 2013 PHP automatically decodes the values in the $_GET (and $_POST) array. Unless you are encoding (via Javascript or something) in addition to what the browser does, there is no need to urldecode() the $_GET (or $_POST) array. @eldan88 ... it says it can't find that specific store name in the "store_name" coloumn What says that? The code you provided could not possibly be saying anything like that. It is more helpful to copy & paste your actual code, than it is to provide a typed-out example that is something-like your code. Show us the real code; Use mysql_error to see the error message (copy and paste the entire message here); echo the actual query and show us what it looks like; Maybe we can help. Quote Link to comment Share on other sites More sharing options...
P5system Posted February 22, 2013 Share Posted February 22, 2013 At the begining when you are assigning $store_name = store1; put this string in quotes like $store_name = "store1"; print the actual query and paste it here Quote Link to comment Share on other sites More sharing options...
eldan88 Posted February 22, 2013 Author Share Posted February 22, 2013 Hey thank you for all your help! I acutally realized in the "where clause" the {store_name} was missing tick marks to mark it was a string. I have put tick marks around it and it worked. =) Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 22, 2013 Share Posted February 22, 2013 Jessica, I apologize I forgot to enter the quotes on store name, when tryping the post. The store name is a $_GET value that gets passed in the function. But everytime it runs the query it says it can't find that specific store name in the "store_name" coloumn. So....you read my post, said you had already done this, and then in the end that was the problem.... Quote Link to comment 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.