3

I'm trying to echo the elements from a database table with a variable name. This means that I want the table with the same name as my session username. I have the following code that gives out a blank page. Plz help!

<?php
session_start();
if(!isset($_SESSION["sess_user"])){
    header("location:./failLogin.php");
}else{
?>
<html>
<?php
        $connection = mysql_connect('localhost', 'root', '');
        mysql_select_db('fchat');

        $result = mysql_query("SELECT * FROM $_SESSION["sess_user"]");

        while($row = mysql_fetch_array($result)){   
            echo "<p><span color="green">" . $row['sender'] . "</span>: " . $row['message'] . "</p><br>";
        }

        mysql_close();
    ?>
</html>
<?php } 
?>
Arjan
  • 9,784
  • 1
  • 31
  • 41
Frank Fourlas
  • 131
  • 1
  • 14
  • 1
    Turn on error reporting. Your code has obvious syntax errors. (Not to mention your code is wide open to SQL injection if that `sess_user` value is a user-defined string, such as a username. And I definitely question the practice of having a separate table for each user...) – David Jun 28 '15 at 12:46
  • You may have seen variations of "Plz help" in other low-quality questions. But that doesn't make it an advisable decoration. – mario Jun 28 '15 at 12:49
  • I really don't care about sql injection hacks and these kind of stuff... im making this for fun. I'm using notepad++ and viewing my work through wamp server so can you tell me how to "turn on error reporting" and not keep saying how nooby and "low-quality" my work is? – Frank Fourlas Jul 08 '15 at 16:55

0 Answers0