wikedawsum Posted January 17, 2007 Share Posted January 17, 2007 I need a new pair of eyes.. or just a new brain.. to tell me why this isn't returning any results. Here's the scenario: I'm setting up a member's website for my company where our customers can login and view custom reports specific to their company, as well as track their "tokens" online and purchase prizes with them. So far I have set up the login page and have gotten it working correctly (thanks to the friendly people on this board). Now I am setting up a reports page that will display their reports. I have set up a mysql database, tokens, which currently has two tables in it.. user and report. My login script pulls information from the user table and sets a session with the username. That session is then passed onto my report page. On my report page, I'm pulling information from the report table. I have set up 3 columns in this table.. username, report_url, and report_name. The username is the same as their login username. I've set up a test user that can login, and have also inserted information into the report table, but when I go to the reports page I cannot see any information. Wow.. I hope I explained that clearly enough.Here's the code for my report.php page:[code]<?phprequire_once('tokens_fns.php');session_start();if (isset($_SESSION['valid_user'])){$username = $_POST['username'];$conn = mysql_connect("", "", "") or die($msg_no_connect);mysql_select_db("tokens") or die(mysql_error()); $res = mysql_query("SELECT * FROM report WHERE username='$username';") or die(mysql_error());do_html_header('');display_user_menu('');check_valid_user('');}?><div id="right"> <div id="title"> <h1>Reports for <? echo $_SESSION['valid_user']; ?></h1> </div> <p>To download your report, click on the report name.</p> <? if (mysql_num_rows($res) > 0) { while ($row = mysql_fetch_assoc($res)) { echo '<table border="0" cellpadding="5">'; echo "<tr> <td><a href='{$row['report_url']}'>{$row['report_name']}</a></td> </tr>"; } echo '</table>';}else echo 'Your reports have not been set up. Please check back soon.';?>[/code]Any ideas, suggestions, comments, critiques? Anything is appreciated! Quote Link to comment Share on other sites More sharing options...
timmah1 Posted January 17, 2007 Share Posted January 17, 2007 I didn't really look at the code, but you really should take out your username, password and address from the script Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 17, 2007 Share Posted January 17, 2007 here $conn = mysql_connect("", "", "").Quick suggestion, you should not post this code publicly... ;)Ted Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 Ack! Completely forgot to take that part out.. Isn't there supposed to be a link to modify your post on here? I'm not seein it.. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 17, 2007 Share Posted January 17, 2007 How is that $username variable getting populated? Is there a form they complete that points to this script that asks for it? Or do they click on a link of some sort after they log in something like ' Click here to view your info' or similar? Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 When they visit the site I have a loing form that they fill out which takes them to a member.php. From there I have a link to the report.php page. If you would like to see it you can visit [url=http://test.aacapartsandsupplies.com]http://test.aacapartsandsupplies.com[/url]. Login is username: test, password: test. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 17, 2007 Share Posted January 17, 2007 Ok, so it's AFTER they log in they have a link they can click on. The simplest way is to do this:[list][*]Change the $username = $_POST['username']; to $username = $_GET['username];[*]In the link to the report, append it with ?username=$username[*]Set a variable on the 'landing' page with the link to the report $username = $_POST['username]; so it populates the variable at the end of the url string[/list]By doing this you're passing the person's username to the query properly and it will locate that user and display their data. Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 Can you explain this a little further?[quote]Set a variable on the 'landing' page with the link to the report $username = $_POST['username]; so it populates the variable at the end of the url string[/quote] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 17, 2007 Share Posted January 17, 2007 "For your convenience, AACA offers six locations throughout the Dallas/Ft. Worth Metroplex."Hey, I live there...maybe I should head over and hand them my card...tell them to get a developer who won't post their login online for everyone to access their php my admin ;)I think we need to mod the forum to allow editing - not just after x seconds or whatever it is, but period. People make mistakes. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 17, 2007 Share Posted January 17, 2007 Sure. Let's go through the logical steps.1. person logs in using username/password combo2. if successful, they get to the 'landing' page which contains this link to their report3. if they click on the link you want it to summon the data for that usernameIf these 3 steps are correct then on the 'landing' page you need to set the $username variable so it can be used again in our link to the report page. So, on the landing page have the variable $username = $_POST['username']; (if that's the login form field name. If not, then change to what your form field name is).Now, you have the $username variable populated when they log in. So, change your link to the report page by just adding the ?username=$username The ? is a operand that PHP recognizes to snag info from the url being passed using the $_GET statement.So, say i've logged in as bozotheclown. When I click on my link to the reports page it will pass my username onto the next page (the reports page and subsequent query display) where you would have the query set up to work off the person's username. Like this:View Your Report! ( report.php?username=bozotheclown would be the actual hyperlink). On the report page place the $username = $_GET['username']; variable at the top of the page and that will retrieve the username that is passed in the url. Then it will use that username in your query:WHERE username='$username' ";Then it will display the report for only that particular username. Make sense? Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 simcoweb:Yes, that makes perfect sense. I actually already had the variable for $username=$_POST['username'] on the landing page. I have made the other changes you suggested and I am still not seeing any data.. ? I understand how it's all supposed to work together so, perhaps another portion of my code is incorrect.jesirose:Yes, people make mistakes. Would have already edited my post if I could. Instead I have just changed the login for my database. :) Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 Also, where I've added ?username=$username.. the link is not displaying the username. It simply displays reports.php?username=$username. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 17, 2007 Share Posted January 17, 2007 Make sure that's not in single quotes. Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 No quotes.. looks exactly like this: <a href="reports.php?username=$username">Reports< /a> Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 17, 2007 Share Posted January 17, 2007 Well that's not PHP, that's HTML. Try <a href="reports.php?username=<?=$username?>">Reports< /a>Or post the whole line of code if it is in PHP. Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 That did get rid of the $username part. This is the HTML for my user menu which is defined in fuction display_user_menu () in output_fns.php[code]<?php}function display_user_menu(){ // display the menu options on this page?> <div id="links"> <h1 class="white">Your Links</h1> <h2><a href="logout.php">Logout</a></h2> <h2><a href="member.php">Member Home</a><br /> <br /> <a href="reports.php?username=<?=$username?>">Reports</a> <br /> <br /> <a href="awards.php">Awards</a><br /> <br /> <a href="http://www.aacapartsandsupplies.com/calendar/cal_login.php" target="_blank">My Calendar</a></h2> </div> <div id="account"> <h1 class="white">Account Information</h1> <h2><a href="profile.php">Profile</a><br /> <br /> <a href="forgot_form.php">Change E-Mail Address</a><br /> <br /> <a href="change_passwd_form.php">Change Password</a> </h2> </div> </div>[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 17, 2007 Share Posted January 17, 2007 Do you understand why you have to do that...You can't just randomly stick php variables in your html and expect it to work... Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 Yes, it makes perfect sense now. Thanks for pointing it out. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 17, 2007 Share Posted January 17, 2007 Did you place the $username = $_GET['username']; on your Reports page? Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 Yes, I did. It looks like this for visual reference..[code]<?phprequire_once('tokens_fns.php');session_start();if (isset($_SESSION['valid_user'])){$username = $_GET['username'];$conn = mysql_connect("mysql.aacapartsandsupplies.com", "bconger", "bmc5106") or die($msg_no_connect);mysql_select_db("tokens") or die(mysql_error()); $res = mysql_query("SELECT * FROM report WHERE username='$username';") or die(mysql_error());do_html_header('');display_user_menu('');}else {echo "You are not authorized to view this page.";}?><div id="right"> <div id="title"> <h1>Reports for <? echo $_SESSION['valid_user']; ?></h1> </div> <p>To download your report, click on the report name.</p> <? if (mysql_num_rows($res) > 0) { while ($row = mysql_fetch_assoc($res)) { echo '<table border="0" cellpadding="5">'; echo "<tr> <td><img src='../images/download_icon.gif' align='left' hspace='10'><a href='{$row['report_url']}'>{$row['report_name']}</a></td> </tr>"; } echo '</table>';}else echo 'Your reports have not been set up. Please check back soon.';?>[/code] Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 17, 2007 Share Posted January 17, 2007 Ok, I noticed an error in your query. You have this:[code]("SELECT * FROM report WHERE username='$username';")[/code]The ; needs to be after the double quotes " like this:[code]"SELECT * FROM report WHERE username='$username' ";[/code]You don't really need the braces either. Try that. Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 Tried that and got the same result. :-\ Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 Btw.. if I change my sql query to username='test' it will bring back the results I want so, I know it is at least connecting to that table correctly. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 17, 2007 Share Posted January 17, 2007 Ok, let's do this. We need to make sure the $username variable is actually being passed. On the reports.php page add this below your $username = $_GET['username']; line.[code]if (isset($username)) { echo "This is the dang username: $username"; } else { echo "There is nothing in this variable";}[/code]If there's nothing there then the username isn't being passed which would explain why there's no results. Quote Link to comment Share on other sites More sharing options...
wikedawsum Posted January 17, 2007 Author Share Posted January 17, 2007 Well.. interestingly enough I got "This is the dang username: "*head desk* 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.