bfsog
06-21-2005, 02:24 AM
Hey. What I am trying do is select rows from a database where a particular column is equal to a variable, which is set to the value of a session variable.
Example query...
$author = $_SESSION['name'];
$query = "SELECT * FROM table_name WHERE column='$author';
However for some reason on this form, $author has no value. So the select does not return anything.
The purpose of my script, well this page at least is to allow users to leave feedback for posts I make. That all works but I cannot get this to work.
This is header.php, it shows different content depending on if you are logged in
<?php
// check if logged in
if (isset($_SESSION['name'])) {
include("db.php");
$author = $_SESSION['name'];
$query = "SELECT * FROM users WHERE username='$author' ORDER BY id";
echo $query;
echo $author; // this comes out as blank
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
echo $numrows;
if ($numrows == "0") {
echo "No codes to display.<br /><br />";} // I get this message
else {
while($row = mysql_fetch_array($result))
{
$profilelink= "<a href='viewprofile.php?id=" . $row['id'] . "'>Your profile</a><br><br>";
}}
?>
And I include that file on feedback.php
Code:
<?php
include("header.php");
?>
So its like the script forgets the session variable value, even though I do have
<?php
session_start();
header("Cache-control: private");
?>
on each page that uses sessions.
Any ideas?
Example query...
$author = $_SESSION['name'];
$query = "SELECT * FROM table_name WHERE column='$author';
However for some reason on this form, $author has no value. So the select does not return anything.
The purpose of my script, well this page at least is to allow users to leave feedback for posts I make. That all works but I cannot get this to work.
This is header.php, it shows different content depending on if you are logged in
<?php
// check if logged in
if (isset($_SESSION['name'])) {
include("db.php");
$author = $_SESSION['name'];
$query = "SELECT * FROM users WHERE username='$author' ORDER BY id";
echo $query;
echo $author; // this comes out as blank
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
echo $numrows;
if ($numrows == "0") {
echo "No codes to display.<br /><br />";} // I get this message
else {
while($row = mysql_fetch_array($result))
{
$profilelink= "<a href='viewprofile.php?id=" . $row['id'] . "'>Your profile</a><br><br>";
}}
?>
And I include that file on feedback.php
Code:
<?php
include("header.php");
?>
So its like the script forgets the session variable value, even though I do have
<?php
session_start();
header("Cache-control: private");
?>
on each page that uses sessions.
Any ideas?