I am trying to store all the unique page content for a website in a table. The problem is that on some pages the content is PHP. MySQL won't seem to let me enter content entered from a form textarea when it contains PHP start or end tags (<?php). The database simply won't update the record. I need to know what needs to be done to make it store records that contain these tags.
You need to know the basics of PHP+MYSQL. Just how far are you now? It would help if you post what you have so far.
You also may wanna take a look at this http: //us2.php.net/eval <----- Remove the space after the colon, I can't post links yet
z0e0u0s is correct. Use eval to run your code after you fetch it from database. Just get the page from DB and check if contains "<?" then run it with eval. The links is http: //us2.php.net/eva
The OP does'nt want to execute the PHP, the OP wan'ts to insert PHP code to the db, theirfore needs to escape it so it can be parsed/inserted into the db.
You will probably find that the query is erroring Depending on whether you're using mysql or mysqli, you can trap the error as follows <? $phpCode = "<?PHP echo \"hello\";?>"; // mysql $db = mysql_connect("server", "user", "pass"); mysql_select_db("mydb", $db); $sql = "INSERT INTO myTable (theField) VALUES ('" . mysql_real_escape_string($phpCode) . "'"; mysql_query($sql) or die("Insert failed: " . mysql_error()); // mysqli $db = new mysqli("server", "user", "pass", "mydb"); $sql = "INSERT INTO myTable (theField) VALUES ('" . $db->real_escape_string($phpCode) . "'"; $db->query($sql) or die("Insert failed: " . $db->error); ?> PHP:
Did you look at the link that Jatar gave you and follow Warboss' advice? I'll warn you that eval isn't a function to cut your php teeth on. When you use it, it's crucial that the argument be valid php code. Try running this test to get the hang of it. [codeHOLD1] The value I've given to $row[0] is the kind of valid code that you'll be required to have in your database in order for eval to work. Getting it in there, however, is another matter. I hope this helps.