0

I am trying to create update function for logged user but I get this kind of error:

invalid query: Unknown column 'johnny' in 'where clause'

can someone help me notify the problem?

<?php
$result = mysql_query("select * from admin where username_admin =".$_SESSION['username_admin']);

if($result) { 
while($row = mysql_fetch_array($result)) {
$_SESSION["username_admin"] = $row['id_admin'];                             

    ?>
   <li>   <a tabindex="-1" href="edit-user.php?id=<?php echo $row['id_admin']; ?>">Edit Account</a>
   </li>

        <?php
        }
        }
        else {
        echo 'invalid query: '.mysql_error(). "\n";

        }

        ?>
awang
  • 13
  • 1
  • 1
  • 6

1 Answers1

0

For sending string to sql, you must wrap it by single quotes:

<?php
$result = mysql_query("select * from admin where `username_admin` ='".$_SESSION['username_admin']."'");

if($result) { 
    while($row = mysql_fetch_array($result)) {
        $_SESSION["username_admin"] = $row['id_admin'];                             

        ?>
        <li>   <a tabindex="-1" href="edit-user.php?id=<?php echo $row['id_admin']; ?>">Edit Account</a>
        </li>

        <?php
    }
}
else {
    echo 'invalid query: '.mysql_error(). "\n";

}

?>
Mohammad Hamedani
  • 3,304
  • 3
  • 10
  • 22