Solved

Why dosent this work ?

Posted on 2013-06-11
6
191 Views
Last Modified: 2013-06-16
Hi!

Have this function in my php file:

function brukerident($bruker_ID)
{
        $uuk = mysql_real_escape_string($_COOKIE["uuk"]);
        $sql = "SELECT Bruker_id FROM brukere WHERE uuk = '$uuk' LIMIT 1";
        $res = mysql_query($sql);
        
        // IF THE QUERY SUCCEEDED
        if ($res)
        {
            // THERE SHOULD BE ONE ROW
            $num = mysql_num_rows($res);
            if ($num)
            {
                // RETRIEVE THE ROW FROM THE QUERY RESULTS SET
                $row = mysql_fetch_assoc($res);

                // STORE THE USER-ID IN THE SESSION ARRAY
                return $row["Bruker_id"];
          
            }
        }
}

Open in new window


This function is called from a another php file:

 $brukerID = brukerident('xxx');

Open in new window


And i have tested that the returnd value is correct.

Value from database is a varchar..

But get an error message from this line:
$result3 = mysql_query("SELECT Navn FROM {$table1} WHERE Bruker_id={$brukerID}") or die(mysql_error());

Open in new window


Error message is:
Unknown column 'K007' in 'where clause'

What is wrong ?
0
Comment
Question by:team2005
  • 3
  • 2
6 Comments
 
LVL 15

Assisted Solution

by:Jagadishwor Dulal
Jagadishwor Dulal earned 500 total points
Comment Utility
What is Navn Data type ?? did you test printing the query.
break the sql to
echo $q="SELECT Navn FROM {$table1} WHERE Bruker_id={$brukerID}";
$r=mysql_query($q) or or die(mysql_error());

Open in new window

I think if the value is varchar insert Bruker_id='$brukerID'

and in your above function why do you are passing parameter $bruker_ID which is not using anywhere in function?

function brukerident($bruker_ID)
{
        $uuk = mysql_real_escape_string($_COOKIE["uuk"]);
        $sql = "SELECT Bruker_id FROM brukere WHERE uuk = '$uuk' LIMIT 1";
        $res = mysql_query($sql);
        
        // IF THE QUERY SUCCEEDED
        if ($res)
        {
            // THERE SHOULD BE ONE ROW
            $num = mysql_num_rows($res);
            if ($num)
            {
                // RETRIEVE THE ROW FROM THE QUERY RESULTS SET
                $row = mysql_fetch_assoc($res);

                // STORE THE USER-ID IN THE SESSION ARRAY
                return $row["Bruker_id"];
          
            }
        }
}

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Where is K007 coming from, it's not present in your queries above.
0
 
LVL 2

Author Comment

by:team2005
Comment Utility
Hi!

The function returns correctly..
Have tested this by using echo...

Tested the output from the query :
SELECT Navn FROM Kontroller WHERE Bruker_id=K007

And that is correct ?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 2

Accepted Solution

by:
team2005 earned 0 total points
Comment Utility
Hi!

The problem was that i must use ' like this:
$result3 = mysql_query("SELECT Navn FROM {$table1} WHERE Bruker_id='{$brukerID}'") or die(mysql_error());
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
Comment Utility
Your error is related to table field
Unknown column 'K007' in 'where clause'
can you fetch the record using above query?
SELECT Navn FROM Kontroller WHERE Bruker_id=K007

Open in new window

I suggest you to use single quote in value like:
SELECT Navn FROM Kontroller WHERE Bruker_id='K007'

Open in new window

0
 
LVL 2

Author Closing Comment

by:team2005
Comment Utility
Thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now