Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Variavles from Mysql 1

Status
Not open for further replies.

david6633

Programmer
Jul 28, 2003
39
GB
I am having a problem with php variables that are stored in a mysql table. If I have
Code:
$text = 'This is some text ' . $var;
echo $text;
Then I have no problems with the $var being replaced with its value but if I pull that same text from my mysql database the output is "This is some text ' . $var" i.e. the $var is printing as text and not being replaced.

I have tried several variants of having quotes (both double and single) in the mysql table, I have also tried escaping the quotes and even type casting the $text variable when it is extracted from the table.

My guess is that it is probably something to do with the implied quotes on the string data from mysql.

I know I am missing something obvious here but I cannot see what it is.

David
Remember: You only know what you know
and - you don't know what you don't know!
 
The something obvious that you are missing is an example of the code that fails!

Andrew
Hampshire, UK
 
Since code in a DB is treated as text by the PHP page that calls it it won;t be run. You need to evaluate it so it can be executed.

The eval function is there to execute code that is contained in a string.









----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks vacunita - eval() was the answer that I was looking for.

David
Remember: You only know what you know
and - you don't know what you don't know!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top