?
Solved

Why dosent this work ?

Posted on 2013-06-11
6
Medium Priority
?
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 15

Assisted Solution

by:Jagadishwor Dulal
Jagadishwor Dulal earned 1500 total points
ID: 39237858
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
ID: 39238007
Where is K007 coming from, it's not present in your queries above.
0
 
LVL 2

Author Comment

by:team2005
ID: 39238061
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
team2005 earned 0 total points
ID: 39238094
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
ID: 39238096
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
ID: 39251051
Thanks
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

801 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