SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast firehawk777's Avatar
    Join Date
    Feb 2011
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Warning: mysql_result() expects parameter 1 to be resource

    Hi there
    I am having a problem with this warning message being thrown
    "Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\css\rnfunctions.php on line 302"
    and again for line 303 though the funny thing is the code does what its supposed to do I.E change the 'level' of user in the database
    Here is the code

    PHP Code:
    function receiveuserchange()
    {
    if (isset(
    $_POST['level'])){
    $query "SELECT * FROM users";
    $result=mysql_query($query) or die("Invalid Query : ".mysql_error());
    $num=mysql_numrows($result);
    $i=0;

    while (
    $i $num) {

    ////////////////here are lines 302 and 303///////////////////////////////
    $user=mysql_result($result,$i,"user");
    $id=mysql_result($result,$i,"id");
    /////////////////////////////////////////////////////////////////////////////

    if (isset($_POST["$user"])){
    $level = ($_POST["$user"]);
    $query "update profiles set level='$level' where pid='$id'";
    $result=mysql_query($query) or die("Invalid Query : ".mysql_error());
    ViewUsers('viewusers.php');
    }else{
    echo 
    "$user not recieved";
    }
    $i++;

    Can anyone see what the problem is?

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,014
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    In the php manual it says:

    Note:
    Calls to mysql_result() should not be mixed with calls to other functions that deal with the result set.
    so chances are it's the use of mysql_num_rows() that is causing the problem. Is the function intended to modify the level of a single user each time it's called?

    Can you do a SHOW CREATE TABLE for the users and profiles tables? It should be possible to update the users level with a single query

    Can you show a
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $level = $_POST['user'];//like this u can pass the value.

    $query = "update profiles set level='$level' where pid='$id'";

    In this query, level value is not updating, because $level value is not set...

  4. #4
    SitePoint Zealot Amit Yaron's Avatar
    Join Date
    Jan 2011
    Location
    Hod Haharon, Israel
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably, because you pass $result as parameter 1, when $result is the result of an Update query. In this case your result will be True upon successful update.
    You can find more information here.

  5. #5
    SitePoint Enthusiast firehawk777's Avatar
    Join Date
    Feb 2011
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Amit Yaron and venkat6134: the query thats having problems is actually the first query which is a SELECT not an UPDATE query.

  6. #6
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $num=mysql_numrows($result);
    here is the problem; $num is not set.
    correct it by;
    $num=mysql_num_rows($result);

  7. #7
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    It seems like you haven't yet understood completely how to query a database and then loop through the result set to fetch and elaborate the extracted data.
    Please take a look at the manual: http://www.php.net/manual/en/functio...etch-assoc.php

    If it's still not clear, don't hesitate to ask more questions

  8. #8
    SitePoint Enthusiast firehawk777's Avatar
    Join Date
    Feb 2011
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guido2004
    It works fine now.
    And thanks everyone else for trying to help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •