Been working on this problem for sometime and I can't seem to find an answer. I am a newbie to PHP so bear with me. Basically I have a php file that needs to set a variable. It pulls the data from template.php which pulls data from mysql. Mysql data contains the variable from the primary file and some randomized text. The problem is that I can't get the mysql variable to show up. You can view it in the source code though.
Here is the main file test.php:
Code: Select all
<?php
session_start();
$keyword="Topic";
$_SESSION['keyword']=$keyword;
include("template.php") ;
?>
Template.php pulls random data from a MySQL db and it works fine except for the variable retrieval:
Code: Select all
<?php
//Connection info deleted
$result = mysql_query($sql_query);
if(mysql_num_rows($result))
{
//output as long as there are still available fields
while($row = mysql_fetch_row($result))
{
echo ("$row[1]");
}
}
//if no fields exist
else
{
echo "no values in the database";
}
?>
Here is a Mysql entry:
Code: Select all
<?php
session_start();
echo $_SESSIONї'keyword'];
?>
Sample random sentences.
This only outputs "Sample random sentences." when I want it to say "Topic Sample random sentences."
Any help would be appreciate! Not sure if session variables are correct.