Jump to content

mysql_result() expects parameter 1 to be resource


whopunk123

Recommended Posts

Hello,

 

I hope that I can get some help here as I have been trying to fix this all day and I think I am going to go mental soon :P

 

Error:

Warning: mysql_result() expects parameter 1 to be resource, string given in /home/cobblecr/public_html/index.php on line 17

 

Code:

<form id="form1" name="index.php" method="GET" action="">
  <p>Username: 
    <label for="usernames"></label>
  <input type="text" name="username" id="usernames" />
  </p>
  <p> 
    <input type="submit" name="Enter" id="Enter" value="Search" />
  </p>
</form>


<?php
include 'connect.php';
$search = $_GET['username'];
echo $search;
$query = "SELECT `balance` FROM `cobblecr_minecraft` WHERE 'username = $search' LIMIT 0, 30 " or die(mysql_error());
mysql_result( $query, 0, 'username');
echo $data;
die()
?>

 

Thanks

Matthew

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

criticizing wont help him rather will make him hate what he is doing, rather help and show him how to do it the right way.

 

lets try this am not so good but am trying to help.

 

<?php
include 'connect.php';
$search = $_GET['username'];
echo $search;
$query = "SELECT `balance` FROM `cobblecr_minecraft` WHERE 'username = $search' LIMIT 0, 30 " or die(mysql_error());
$results = mysql_query($query);
$data = $results['balance'];
echo $data;
die()

Link to comment
Share on other sites

Ok thanks you two you have been of great help I have now lost that error but could you help with echoing out the data it gets from the mysql query.

 

All it outputs is "whopunk123Resource id #3"

I have tried a few things none of them worked

I have changed my code so it now looks like this

 

<?php
include 'connect.php';
$search = $_GET['username'];
echo $search;
$query = "SELECT `balance` FROM `cobblecr_minecraft` WHERE 'username = $search' LIMIT 0, 30 " or die(mysql_error());
$results = mysql_query($query);
$data = $results['balance'];
echo $data;
die()
?>

 

Thanks again for the help I had already

Link to comment
Share on other sites

It's commendable that you want to help, hakimserwa, and I applaud you for that.

However, not only is the code you gave him wrong, but it's also wide open for SQL injections. So what you're doing is actually a disservice, in that you're not only confusing the matter further but also teaching insecure methods. That's why I'll ask you to please make sure that the code you're posting is correct and secure, if you want to help someone in the future.

 

Also, I didn't criticise just for the sake of criticism. I told him what he needed to do, and where he needed to look. We can't help anyone if they're not willing to spend all of the effort, and attention(!), needed to learn. Since the problems he's having are quite basic, and very well explained in the manual, that's where he needs to look for answers.

Link to comment
Share on other sites

Since the problems he's having are quite basic, and very well explained in the manual, that's where he needs to look for answers.

 

if you feel that you dont want to help because the problem is so basic then leave the post because further down the line there you are with more of your critisim. every one starts somewhere remember, you also sometimes back you were like we so mr master whet you call basic might be what is causing trafic jam for another. the board is so big leave the basic question to those willing to help.

 

Please delet the die() function. and also do you have data in the database?

Link to comment
Share on other sites

Since the problems he's having are quite basic, and very well explained in the manual, that's where he needs to look for answers.

 

if you feel that you dont want to help because the problem is so basic then leave the post because further down the line there you are with more of your critisim. every one starts somewhere remember, you also sometimes back you were like we so mr master whet you call basic might be what is causing trafic jam for another. the board is so big leave the basic question to those willing to help.

 

Please delet the die() function. and also do you have data in the database?

 

I will and I do have data in the database.

 

Also sorry moderator for the trouble this is making.

Link to comment
Share on other sites

If I'm correct, you need to use an actual mysql_query function as the 1st parameter.

 

So try this:

 

$query = "SELECT `balance` FROM `cobblecr_minecraft` WHERE 'username = $search' LIMIT 0, 30 " or die(mysql_error());

$runQuery = mysql_query($query);

mysql_result( $runQuery, 0, 'username');

Link to comment
Share on other sites

change the query  die after closing ) of the select query.


$query = mysql_query("SELECT `balance` FROM `cobblecr_minecraft` WHERE 'username = $search' LIMIT 0, 30 ") or die(mysql_error());

@hakim, please, don't post wrong solutions.

Link to comment
Share on other sites

change the query  die after closing ) of the select query.


$query = mysql_query("SELECT `balance` FROM `cobblecr_minecraft` WHERE 'username = $search' LIMIT 0, 30 ") or die(mysql_error());

@hakim, please, don't post wrong solutions.

 

i cant say no because i am also learning but whats wrong with that query.

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.