Jump to content

Recommended Posts

I have a log-in script that after loging in takes the user to a 'product page.' On that 'product page' it says "Welcome 'username' " and that part works fine.

 

What I'm trying to add to the page for a list of the users $rows in a MySQL db to show on the page also.

 

This is the code I'm using welcome or kick the user. (this one works fine)

<?php 
if(!$_SESSION['username'] && !$_SESSION['password']) {
echo '<span style="border: #000 1px solid; background-color: #CCCCCC">
     <center>Welcome, <b>'.$username.'</b>  
     Redirecting you....</center></span>
     <meta http-equiv="refresh" content="2;URL=pass/index.php" />';
  }
else { echo 'Welcome  '.$_SESSION['username'].'';
}?>

This is the code I trying to use that'll pull the info from the db

<?php 
$query = "SELECT * FROM images WHERE user="$_SESSION[.'username'.]" Order By id";

include("config.php");

$result = mysql_query($query) or die(mysql_error());

mysql_close();

$output = "
<html>
<body>
<table>

<thead>
<td>Id/Order</td>
<td>Address</td>
</tr>
</thead>
";

 

I might mention that the 2nd bit of code works fine when I hard code in a User's ID...so I know that it's seeing the db, it just when I try to re-use the variable of username that I get this error.

Unknown column 'username' in 'where clause

Any suggestions would be great.

Link to comment
https://forums.phpfreaks.com/topic/2026-client-orders-after-log-in/
Share on other sites

Well yeah at very least this line is wrong:

 

$query = "SELECT * FROM images WHERE user="$_SESSION[.'username'.]" Order By id";

 

 

To be honest that isn't even valid PHP and I don't understand how that could even be parsed and not return a php error.

 

The line you want would be this:

 

$query = "SELECT * FROM images WHERE user= '$_SESSION[username]' Order By id";

Thank you...that solved the error problem that I was having. However, the end result is not what I expected. Rather than only the records that belong to that user, I'm getting a list of all records in the database regardless of who they belong to.

 

Any Suggestions would be appreciated.

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.