Jump to content

please help!


wikedawsum

Recommended Posts

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]<?php

require_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!
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

"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.
Link to comment
Share on other sites

Sure. Let's go through the logical steps.

1. person logs in using username/password combo
2. if successful, they get to the 'landing' page which contains this link to their report
3. if they click on the link you want it to summon the data for that username

If 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?
Link to comment
Share on other sites

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.  :)
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

Yes, I did. It looks like this for visual reference..

[code]<?php

require_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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.