Jump to content

PHP Script from MySQL Database or TXT file !


Fahid

Recommended Posts

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 !

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.