0
function DisplayPoints()
    {   

    $con = mysql_connect("localhost", "grame2_admin", "password") ;
    if (!$con) {
    die("Can not connected: " . mysql_error());
    }
    mysql_select_db("grame2_webpage",$con);
    $sql = "SELECT points FROM tablename WHERE username = $username";
    $myData = mysql_query($sql,$con);
    while($record = mysql_fetch_array($myData)){    

It echo out info, that there is error in line 164, LINE ABOVE THIS.

    echo $record['points'] ;

    }
    mysql_close($con);

}

the main idea is to echo out INT from specific user in webpage. Please help! :)

3
  • IF you get an error you should post it here so that other user know what error you get and can help you Commented Jun 22, 2013 at 9:24
  • Thanks it doesnt show error now, but it doesnt show INT . I want to see it, what i'm doing wrong? Commented Jun 22, 2013 at 9:36
  • @EmilMorris Is it a complete code for that function? Where $username variable is defined? Commented Jun 22, 2013 at 9:52

1 Answer 1

1

Change

$sql = "SELECT points FROM tablename WHERE username = $username";

to

$sql = "SELECT points FROM tablename WHERE username = '$username'";
                                                      ^         ^

On a side note use prepared statements with either mysqli or PDO. mysql extension is deprecated and is no longer supported.

UPDATE The other problem is that your $username variable is not initialized. You probably need to pass it to your function as a parameter

function DisplayPoints($username) 
{
    ...
}

And when you call your function pass a value

DisplayPoints('user1');

or

$username = $_POST['username'];
// here should go code to validate and sanitize $username
DisplayPoints($username);
Sign up to request clarification or add additional context in comments.

5 Comments

It's hard to tell from the code that you posted. Did you try to execute your query directly in mysql?
forgive, but I did not understand what you mean by that
I mean did you try to execute the query SELECT points FROM tablename WHERE username = '<substitute with the value from $username' using phpmyadmin or mysql command line utility or any other client tool for mysql? You may not have a record with a username that is assigned to $username variable. Or $username variable can contain wrong value or contain no value.
No I havent. Where i need to assign it- somewhere in phpmyamdin or in function DisplayPoints() code? and what i have to do to assign it? Mabe there is some tutorial in web that you know?
HOLLLY SH*T! YOU ARE THE BEST, IT WORKED. BIG, BIG THANKS BRO, RESPECT. :) :) :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.