whopunk123 Posted July 30, 2012 Share Posted July 30, 2012 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 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 30, 2012 Share Posted July 30, 2012 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 Quote Link to comment Share on other sites More sharing options...
whopunk123 Posted July 30, 2012 Author Share Posted July 30, 2012 Should it look more like this? mysql_result( $query ['username']); Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 30, 2012 Share Posted July 30, 2012 Did you even look? Quote Link to comment Share on other sites More sharing options...
whopunk123 Posted July 30, 2012 Author Share Posted July 30, 2012 Yes I am new to PHP so I'm still learning the ropes Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 30, 2012 Share Posted July 30, 2012 So what do the examples on that page look like? Quote Link to comment Share on other sites More sharing options...
whopunk123 Posted July 30, 2012 Author Share Posted July 30, 2012 They use a variable to preform the query? Quote Link to comment Share on other sites More sharing options...
whopunk123 Posted July 30, 2012 Author Share Posted July 30, 2012 More like this: $query = sprintf("SELECT `balance` FROM `cobblecr_minecraft` WHERE 'username = $search' LIMIT 0, 30 ", mysql_real_escape_string($search)); Quote Link to comment Share on other sites More sharing options...
Christian F. Posted July 30, 2012 Share Posted July 30, 2012 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. Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted July 31, 2012 Share Posted July 31, 2012 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() Quote Link to comment Share on other sites More sharing options...
whopunk123 Posted July 31, 2012 Author Share Posted July 31, 2012 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 Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted July 31, 2012 Share Posted July 31, 2012 Why did you put in die() in the end of the query string ? This does not make sense it supposed to be in the end of mysql_query function. Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 31, 2012 Share Posted July 31, 2012 Look at the example on the page and make your code look EXACTLY like it but with your own query. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted July 31, 2012 Share Posted July 31, 2012 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. Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted July 31, 2012 Share Posted July 31, 2012 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? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 31, 2012 Share Posted July 31, 2012 If this thread continues its downward spiral, it will be locked. Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted July 31, 2012 Share Posted July 31, 2012 sorry mod it wont Quote Link to comment Share on other sites More sharing options...
whopunk123 Posted August 3, 2012 Author Share Posted August 3, 2012 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 3, 2012 Share Posted August 3, 2012 Make your query look exactly like the example on the page I showed you, and post that code here. Quote Link to comment Share on other sites More sharing options...
pseud Posted August 3, 2012 Share Posted August 3, 2012 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'); Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 3, 2012 Share Posted August 3, 2012 If you have no idea what you're doing, don't post BAD help. You guys are stuck on putting the or die() in the wrong spot for one thing. Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted August 4, 2012 Share Posted August 4, 2012 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()); Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 4, 2012 Share Posted August 4, 2012 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. Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted August 4, 2012 Share Posted August 4, 2012 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. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 4, 2012 Share Posted August 4, 2012 Okay, try to find yourself the error I'm a beginner too, but if I want to post an answer I have to be sure a 100% that does make sense and without errors. 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.