Solved

Why dosent this work ?

Posted on 2013-06-11
6
197 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
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
Industry Leaders: 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

685 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