PDA

View Full Version : insert php code into mysql


FrEaKmAn
August 8th, 2006, 10:12 AM
Hi

I would like to add php code into mysql database. I found one tutorial but I can't get it to work. This is the code

<?php
include 'config.php';

$result = mysql_query("SELECT * FROM test");
list($text) = mysql_fetch_array($result);


/*$text = '<?php include "1.php"; ?>';*/

eval('?>'.$text.'<?php');

?>

and mysql data

CREATE TABLE `test` (
`text` longtext
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `test` (`text`) VALUES ('<?php include \\"1.php\\"; ?>');

and I get this error


Warning: Unexpected character in input: '\' (ASCII=92) state=1 in ...index.php(10) : eval()'d code on line 1

Parse error: parse error, unexpected $end in ...index.php(10) : eval()'d code on line 1

degsy
August 8th, 2006, 10:15 AM
What tutorial are you following?

FrEaKmAn
August 8th, 2006, 10:17 AM
http://www.zimmertech.com/tutorials/php/51/evaluate-php-code-from-mysql.php

degsy
August 8th, 2006, 10:23 AM
Are you manually inserting those backslashes? Remove them. They are causing the error.
If not then check what your php.ini settings to see if you have magic quotes enabled.

FrEaKmAn
August 8th, 2006, 10:26 AM
thanks, for all others, I changed

; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = On

FrEaKmAn
August 8th, 2006, 11:11 AM
Well now when I want to inlcude this into my script I get error again.


Warning: include(news.php?include) [function.include]: failed to open stream: Invalid argument in ...index.php(12) : eval()'d code on line 1

Warning: include() [function.include]: Failed opening 'news.php?include' for inclusion (include_path='.;C:\php5\pear') in ...index.php(12) : eval()'d code on line 1


</b>What I want to do is to make header, leftside, rightside and footer on every page and on one include news. I made script with


if(isset($include)){ ... get data out ...}

and now I want to include news.php?include

FrEaKmAn
August 8th, 2006, 12:28 PM
Well I replaced news.php?include and I made simple news_include.php and it works..