The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Help with PHP function
tyler.watkins
post Jun 18 2012, 11:43 AM
Post #1


Novice
**

Group: Members
Posts: 27
Joined: 6-March 12
Member No.: 16,654



I have this function
CODE
function getuserfield($field)
{
    $query = "SELECT '$field' FROM `users` WHERE `ID`='".$_SESSION['user_id']."'";
    
    if($query_run = mysql_query($query))
    {
        if($query_result = mysql_result($query_run, 0, $field))
        {
            return $query_result;
        }
    }
}

But when i call the function and add a parameter such as "firstname" EX. <?php getuserfield('firstname'); ?> it just writes "firstname" to my page instead of actually writing the users first name.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Jun 19 2012, 01:13 PM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



Debugging. Debugging. Debugging. That's what you have to do.

What is the SQL query actually being sent? After setting $query, echo $query (you need to add "<p>query: " or something to make it look reasonable.

What result does mysql_query() return? Success or failure?

And so on.

Programs are not written by Very Skilled people just staring at them.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 24th April 2024 - 03:35 PM