#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Resource id # 366 error I am getting


    Hello every one,
    I am using PHP script in Wordpress for displaying logged in user details in the site home page. I can successfully get username,email,display name etc., from current_user global function. Now, with in the same page php code I am trying to get custom table information based on logged in user email primary key. But I am getting the error as result= Resource id #366.
    Please support this issue.
    I have a custom table "memberlevel" have primary key column as user_email I have written sql query for memberlevel table and wp_users default wordpress table like this

    $presentlevelsql= ("SELECT level FROM $db_table WHERE user_email='$current_user->user_email'");

    Thank you so much in advance for your valuable time spending for me.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    What exactly does the error message say? What happens when you output the query and execute it in phpmyadmin?

    Also you should be much more careful with inserting variables in queries. If you don't escape them, your code will be vulnerable to SQL injections (that is, an attacker can manipulate your query and try to steal information).
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    That's not an error, you're forgetting a step in your code.

    The resource ID error is in the new user guide.

    v----------- Right Here ------------v
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    I want to display current logged in user details from a database in wordpress sitepag


    Hello,
    Thank you so much for your valuable replies. Actually I have build a site in wordpress with buddypress. I have created a table in the database for any user logged in and attend a test in the site that table have been updated. Now, my requirement is I have created one menu for logged in user knowing his test result. When any logged in user click on that menu I want to show his details from that previous table. I have pasted my code below please support me for this issue. Thank you so much for your valuable support.

    ************

    <?php
    $hostname = "localhost";
    $db_user = "xxxxxxxxx";
    $db_password = "xxxxxxxx";
    $database = "xxxxxxxxxx";

    $db_table = "dailychecklist";



    $db = mysql_connect($hostname, $db_user, $db_password);




    if (! $db) die(mysql_error());

    mysql_select_db($database,$db);


    global $current_user;
    get_currentuserinfo();
    echo 'email: ' . $current_user->user_email . "\n";
    $loggedemail = $current_user->user_email;



    $result = mysql_query( "SELECT * FROM $db_table where email='$loggedemail'" )
    or die("SELECT Error: ".mysql_error());
    $num_rows = mysql_num_rows($result);
    print "There are $num_rows records.<br>";

    print "<table width=600 border=1>\n";
    while ($get_info = mysql_fetch_row($result)){
    print "<tr>\n";
    foreach ($get_info as $field)
    print "\t<td>$field</td>\n";
    print "</tr>\n";
    }
    print "</table>\n";
    mysql_close($db);
    ?>


    Thanks in advance for your valuable support,
    Mahesh.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Location
    Jersey
    Posts
    16
    Rep Power
    0
    At which point are you getting the error. I ran the code on my local db but commented out the global $current_user; TO $loggedemail lines because I don't have that code. If you comment out those lines does it work for you? If it is choking on those linnes can you provide the code for those functions?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    Hello danramosd,
    Thank you so much for your valuable reply. In my wordpress site database I have default database table wp_users with in this I have user_email column. And I have custom table for users test competition details updation in this table also I have created email column. Now I am trying to use where clause in mysql for email for showing current logged in user details.
    Now, I am trying to display current logged in user details from custom table by using mysql command like this


    *************
    <?php
    /* Change next two lines if using online*/


    //global $current_user;
    //get_currentuserinfo();

    //echo 'Welcome to: ' . $current_user->user_login . "\n";
    //echo 'email: ' . $current_user->user_email . "\n";
    //echo 'Member from: ' . $current_user->user_registered . "\n";

    //$logged = $current_user->user_login;
    //$loggedemail = $current_user->user_email;





    $hostname = "localhost";
    $db_user = "harvamin_harvam";
    $db_password = "H@r1vam2";
    $database = "harvamin_om";
    //$db_table = "custtable";
    //$order_table = "order";

    $db_table = "dailychecklist";



    $db = mysql_connect($hostname, $db_user, $db_password);



    //$db="newdb";
    //$link = mysql_connect('localhost', 'root', '');

    if (! $db) die(mysql_error());
    //mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());
    mysql_select_db($database,$db);

    $result = mysql_query( "SELECT * FROM $db_table where email='admin@infratran.com'" )
    or die("SELECT Error: ".mysql_error());


    //$result = mysql_query( "SELECT * FROM $db_table where dailychecklist.email=$current_user->user_email" )
    //or die("SELECT Error: ".mysql_error());

    //$loggedemail = $current_user->user_email;


    $num_rows = mysql_num_rows($result);
    print "There are $num_rows records.<br>";

    print "<table width=600 border=1>\n";
    while ($get_info = mysql_fetch_row($result)){
    print "<tr>\n";
    foreach ($get_info as $field)
    print "\t<td>$field</td>\n";
    print "</tr>\n";
    }
    print "</table>\n";
    mysql_close($db);
    ?>


    I have commented that global $current_user function code lines because wordpress phpexec plugin didnit support like that error I have got. So, please support this issue. I have tried so many cases.

    Thanks in advance for your valuable time for me,
    Mahesh,

    Comments on this post

    • ManiacDan disagrees : Answer the questions that are asked of you.
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Read the new user guide and at least attempt to answer the questions you are asked. He asked you a direct question, you ignored it. Pasting your code over and over again is not the solution, especially since you continue to paste your code incorrectly, unformatted, and uncolored.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Location
    Jersey
    Posts
    16
    Rep Power
    0
    A couple things:
    I have to comment the same lines again because I don't have access to the source code of your global $current_user variable along with get_currentuserinfo() function. This puts me back to square 1 because when I comment out the same lines it works for me.

    With that being said your sql commands seem to work fine when I run it on a test DB locally. I would recommend you comment out all of the DB related queries and make sure the $current_user variable is giving you all the data you expected. Instead of using variables try hard coding in the values you expect the variables to be. For example instead of:

    PHP Code:
    $loggedemail $current_user->user_email
    Try

    PHP Code:
    $loggedemail 'foo@bar.com'
    This wil allow you to start narrowing down your issues.

    If you're still running into issues please provide a MySQL dump of your database table(s).

    Finally, assuming you're running PHP5 i highly recommend using mysqli VS mysql for all your queries, or possibly even looking into other methods. Google around mysqli vs mysql to read why (i would post a link but apparently news users aren't allow)

IMN logo majestic logo threadwatch logo seochat tools logo