Jump to content

mysql_result() expects parameter 1 to be resource


whopunk123

Recommended Posts

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());

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 :o 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

Link to comment
Share on other sites

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 :o 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.

Link to comment
Share on other sites

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 :o 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.

Link to comment
Share on other sites

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 :o 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. :facepalm:

 

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.

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.