Help with PHP function |
Help with PHP function |
tyler.watkins |
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. |
Brian Chandler |
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. |
Lo-Fi Version | Time is now: 24th April 2024 - 12:13 AM |