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
Solved

Why dosent this work ?

Posted on 2013-06-11
6
195 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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 …

861 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