Fahid Posted April 2, 2008 Share Posted April 2, 2008 1. Can we obtain some text (PHP Script) from a database and execute it? If yes then how? Example-1 - Fetching Data/PHP Script from data base <?php $query = "SELECT `code`, `codename` FROM `tablename` WHERE `codename`='error_from' LIMIT 1;"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result) > 0){ while($output = mysql_fetch_array($result)){ $script = $output['code']; } } // now $script has some PHP script in it, // can we some how execute this script, if yes then how? ?> 2. Can we obtain some text (PHP Script) from a text file with fopen/fread and execute it? If yes then how? Example-2 - PHP Code from text file <?php $file = "texts/report-error-form.txt"; $fp = fopen($file,"r"); $script = fread($fp, 4096); fclose($fp); // now $script has some PHP script in it, // can we some how execute this script, if yes then how? ?> Please help ! Link to comment https://forums.phpfreaks.com/topic/99106-php-script-from-mysql-database-or-txt-file/ Share on other sites More sharing options...
sequalit Posted April 2, 2008 Share Posted April 2, 2008 you can write the code to a file and then include('/path/to/filename'); Link to comment https://forums.phpfreaks.com/topic/99106-php-script-from-mysql-database-or-txt-file/#findComment-507087 Share on other sites More sharing options...
Fahid Posted April 2, 2008 Author Share Posted April 2, 2008 I want to get the contents of the file/db_data into a variable, because it has both HTML and some PHP script. I want to save this data into variable so that I can print the data on a specific spot in my page. If I use your method, PHP Script will be executed, but HTML will be sent to browser right away, which I don't want. here are contents of PHP script I want to add through TEXT FILE or MYSQL DATABASE <div id="reporterrorform"> <form method="post" action="report-error.php"> <fieldset> <legend>Report Error...</legend> <table> <tr> <td colspan="2" align="center"><hr /></td> </tr> <tr> <th><label for="PageAddress">Page Address: </label></th> <td><input type="text" name="PageAddress" id="PageAddress" size="60" readonly="readonly" value="<?php isset($PageAddress) ? echo $PageAddress : echo $_SERVER['HTTP_REFERER']; ?>" /></td> </tr> <tr> <th valign="top"><label for="Description">Description of Error: </label></th> <td><textarea rows="6" cols="45" name="Description" id="Description"><?php echo $Description; ?></textarea></td> </tr> <tr> <td colspan="2"><p class="formhelp">Thank You for taking your time to Report the Error.</td> </tr> <tr> <th><label for="Name">Full Name: </label></th> <td><input type="text" name="Name" id="Name" size="60" maxlength="30" value="<?php echo $Name; ?>" /></td> </tr> <tr> <th><label for="Email">Email Address: </label></th> <td><input type="text" name="Email" id="Email" size="60" maxlength="60" maxlength="30" value="<?php echo $Email; ?>" /></td> </tr> <tr> <th><label for="Phone">Phone/FAX/Cell: </label></th> <td><input type="text" name="Phone" id="Phone" size="60" maxlength="60" maxlength="30" value="<?php echo $Phone; ?>" /></td> </tr> <tr> <td align="right"><input type="submit" value="Send" /></td> <td><input type="reset" value="Clear" /></td> </tr> </table> </fieldset> </form> </div> Link to comment https://forums.phpfreaks.com/topic/99106-php-script-from-mysql-database-or-txt-file/#findComment-507096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.