Page 1 of 1

How do I Pass a variable into MySQL?

Posted: Tue Apr 06, 2004 3:21 pm
by ghank
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

&lt;?php 
session_start(); 
echo $_SESSION&#1111;'keyword']; 
?&gt;

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.

Posted: Tue Apr 06, 2004 3:26 pm
by ol4pr0
did you check whatever info youre database has.. ?

Does it really have ' Topic' ?

Posted: Tue Apr 06, 2004 3:36 pm
by ghank
My database doesn't have 'Topic'. Maybe I confused you. Basically test.php sets the variable to Topic then loads or Includes template.php which queries the database. And the database has php code in it to display the variable and some random text.