How do I Pass a variable into MySQL?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ghank
Forum Commoner
Posts: 35
Joined: Tue Apr 06, 2004 3:21 pm

How do I Pass a variable into MySQL?

Post 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.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

did you check whatever info youre database has.. ?

Does it really have ' Topic' ?
ghank
Forum Commoner
Posts: 35
Joined: Tue Apr 06, 2004 3:21 pm

Post 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.
Post Reply