Solved

Why dosent this work ?

Posted on 2013-06-11
6
199 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 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

690 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