Page 1 of 1

Inserting PHP code into mysql as part of the query

Posted: Fri Jul 22, 2005 5:28 pm
by tahseenzafar
Hey Guys,
this problem is making me go nuts.
I am trying to do
$query= "insert into page(content) VALUES ('<? include('main.php'); ?> ');
now i know that doesnt work, But i have tried putting in character code for the question mark, the quotes..nothing works.
can you tell me how i can make this work? it works fine on phpMyAdmin
thanks
sincerely,

Posted: Fri Jul 22, 2005 6:42 pm
by timvw
If you want to contents of the document:

Code: Select all

$contents = file_get_contents('main.php');
If you want the parsed output of the document:

Code: Select all

ob_start();
include('main.php');
$contents = ob_get_contents();
After that santize it

Code: Select all

$contents = mysql_real_escape_string($contents);

Posted: Fri Jul 22, 2005 11:56 pm
by jmut
I guess your question is quoting problem?
Try this:

Code: Select all

$query = 'INSERT INTO page(content) VALUES '. include ('main.php');.'';
Note: Quotes at the and is ' ' and not ".
You don't need to open another php tag.