lamajlooc Posted October 21, 2006 Share Posted October 21, 2006 Hi,I'm trying to write a script where after loggin in, some of the stored data of a user is read from a SQL table and then printed to their page. So it has to be dynamic to whoever is logged in. I'm new at this so any help would be greatly appreciated.The query I have is:$query = "SELECT username, daily_score, agg_score, av_score, winner, times_won, win_circle, date_last_in FROM users WHERE username = $_SESSION['username']";I guess it's a problem with the qotes...but I've tried different combos with escaping and I can't figure it out. Of course, maybe how I've written it isn't allowed?Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Jocka Posted October 21, 2006 Share Posted October 21, 2006 change that last part to this:username = '" . $_SESSION['username'] . "'That should get it.. asumming the user is logged in of course. Quote Link to comment Share on other sites More sharing options...
akitchin Posted October 21, 2006 Share Posted October 21, 2006 or, if you have a lot of arrays and don't feel like escaping, you can always enclose array names inside braces:[code]$query = "SELECT username, daily_score, agg_score, av_score, winner, times_won, win_circle, date_last_in FROM users WHERE username = '{$_SESSION['username']}'";[/code]always good practice to keep any data that the user could potentially edit in single quotes. Quote Link to comment Share on other sites More sharing options...
lamajlooc Posted October 22, 2006 Author Share Posted October 22, 2006 Thanks guys, that helped, but I have one quick question. When I read the data from the DB, it seems like the only data that's being read is the first two table rows (first_name) and (username). Have any idea why that might be? Also, I use a while loop to print out all the data. I've used this same code before and it worked fine but for some reason now it seems to not print anyhting. I don't get any errors when I run the code either.Here is the script:<?php # the user index page require_once ('../includes/config.inc'); $page_title = "Welcome Home"; include_once ('../includes/header.html'); require_once ('../not_web/mysql_connect.php'); $query = "SELECT first_name, username, daily_score, agg_score, av_score, winner, times_won, win_circle, date_last_in FROM users WHERE username = '{$_SESSION['username']}'"; $result = @mysql_query($query); $bg = '#eeeeee'; // This is so that each iteration of the while has a different background color. echo "Welcome {$_SESSION['first_name']}"; print_r($_SESSION); //This only prints the first_name and username nothing else while ($row = mysql_fetch_array($result, MYSQL_NUM)) { //This does not return any errors, but also does not return anything. $bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee'); echo '<span style="background:', $bg, ';">', stripslashes($row[0]), '</span><br />'; } mysql_free_result($result); mysql_close(); include_once('../includes/footer.html');?>Thanks again for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.