hakimserwa Posted August 4, 2012 Share Posted August 4, 2012 after looking i noticed your concirn this right 'username = $search' that was in the code since the begining of the post i only tried to fix the position of the die which has been a problem too. any way lets fix it. $query = mysql_query("SELECT balance FROM cobblecr_minecraft WHERE username = $search LIMIT 0, 30 ") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2012 Share Posted August 4, 2012 The query posted in reply #8 is the only query in this thread that is error free and logically correct. Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted August 5, 2012 Share Posted August 5, 2012 The query posted in reply #8 is the only query in this thread that is error free and logically correct. really if am still getting this wrong then i dont know is that simple query still wrong mod? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 5, 2012 Share Posted August 5, 2012 Literal string data in a query must be enclosed in single-quotes so that it is treated as a string instead of being treated as a keyword or a table/column identifier. Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted August 5, 2012 Share Posted August 5, 2012 let me get this clear because it does work when i tested it. is it a great programers' practice or it wont even work? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 5, 2012 Share Posted August 5, 2012 User names, by convention, are strings consisting of alphanumeric and special characters. The query you posted would produce an error - Unknown column 'the entered username' in 'where clause', because the $search term is not enclosed within single quotes and is being treated as a column name instead of a piece of string data. If you tested something that worked, it wasn't what the OP is doing in this thread. In fact, he is testing with his username - whopunk123 (see reply #10) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 5, 2012 Share Posted August 5, 2012 @whopunk123, here's a summery of the replies in this thread that you need to review - reply #1 You put your or die in the wrong spot. You have it after you declare a string, it needs to be after you try to USE the string. Which you're also not doing correctly. GO look at the examples on mysql_query reply #3 Did you even look? reply #5 So what do the examples on that page look like? reply #8 Corrected version of whopunk123's example: $query = sprintf("SELECT `balance` FROM `cobblecr_minecraft` WHERE `username` = '%s' LIMIT 0, 30 ", mysql_real_escape_string($search)); That's for generating the SQL query you want to use, now you need to send it to the database with mysql_query (). How it's done is very easily explained in the PHP manual, but you do need to pay attention to all of the details. Programming is something that takes time, dedication and lots of planning. So a lot of patience and willingness to learn is highly recommended. These replies were an attempt to get you to actually look at and think about your code, look at the official php.net documentation showing how to use the mysql_query statement, and to point out specific problems or omissions in your code (i.e. to learn.) Everything after reply #8 either served to derail the thread, was in error, was off topic, or was to point out or undo problems created by the replies. If you are still having problems with your code after following the advice given to you in replies #1, #3, #5, and #8, post your current code, keeping in mind that it should be similar to the Example #2 Valid Query mysql_query code that jesirose linked to in the php.net documentation, along with a statement of any symptoms or errors you are getting when you run your code. Quote Link to comment Share on other sites More sharing options...
pseud Posted August 6, 2012 Share Posted August 6, 2012 The problem I'm seeing is that he is using mysql_result() with the variable containing the query, not a variable containing mysql_query(the query); - So the parameter for the function is wrong. Can anyone else not see this? It's typical for this error message, why has nobody else said this yet? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 6, 2012 Share Posted August 6, 2012 That's exactly what jesirose's response in the very first reply in the thread was pointing out. Quote Link to comment Share on other sites More sharing options...
pseud Posted August 6, 2012 Share Posted August 6, 2012 That's exactly what jesirose's response in the very first reply in the thread was pointing out. The 1st reply states that he has his die(); in the wrong place, which isn't the problem at all I'm not trying to rage at anyone, or anything like that, I'm just asking why everyone is talking about the die(); function when that's not the problem xD Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted August 6, 2012 Share Posted August 6, 2012 That's exactly what jesirose's response in the very first reply in the thread was pointing out. The 1st reply states that he has his die(); in the wrong place, which isn't the problem at all I'm not trying to rage at anyone, or anything like that, I'm just asking why everyone is talking about the die(); function when that's not the problem xD The die() is written at the end of an assignment statement, not a function invocation. It will always die at that spot. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 6, 2012 Share Posted August 6, 2012 That's exactly what jesirose's response in the very first reply in the thread was pointing out. The 1st reply states that he has his die(); in the wrong place, which isn't the problem at all I'm not trying to rage at anyone, or anything like that, I'm just asking why everyone is talking about the die(); function when that's not the problem xD You put your or die in the wrong spot. You have it after you declare a string, it needs to be after you try to USE the string. Which you're also not doing correctly. GO look at the examples on mysql_query You should read it again. Quote Link to comment Share on other sites More sharing options...
pseud Posted August 6, 2012 Share Posted August 6, 2012 Ahh, I misread it Thanks Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted August 6, 2012 Share Posted August 6, 2012 That's exactly what jesirose's response in the very first reply in the thread was pointing out. The 1st reply states that he has his die(); in the wrong place, which isn't the problem at all I'm not trying to rage at anyone, or anything like that, I'm just asking why everyone is talking about the die(); function when that's not the problem xD The die() is written at the end of an assignment statement, not a function invocation. It will always die at that spot. Wow, did I screw this one up. I didn't read through the OP's code with the attention/diligence it required, and, as a result, gave a really horrible and incorrect answer. So, to the community at large, and to my fellow staff, I apologize. I hold myself to a higher standard that was displayed here, and this will serve as a good reminder to not slack off. I also believe that since I take other members' lazy/incorrect answers to task publicly, it's only fair that I own up to my own lazy and incorrect answer publicly. So, once again, I apologize. --- That said, I think it would be good if we found out from whopunk123 exactly what they want to do with the data. I mean, they're trying to get up to 30 rows of the 'balance' column. Is that data supposed to be added together? Output one row at a time? Getting the full picture will allow us to give a better answer. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 7, 2012 Share Posted August 7, 2012 @off you guys are the best. The best forum that I've ever seen! I'm glad to be a part of you 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.