Variables in variables?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a little more specific:

I have a template in the database which looks something like this:

<html>
<title>$page_title</title>

<body>

Image: $image <p />
<img src = \"$image\">

Main Text: $mtext <br />
Text2: $text2 <br />
Text3: $text3 <br />

</body>
<html>

The variable name is $somecontent

When I call $somecontent in the PHP file, it displays exactly like it is
above. It does not replace the variables.

Is there a reason for this?

Here is my PHP file:



<?php

include "cnx.php";
include "includes/header.php";

//Include the content
$select_data = "SELECT * FROM template WHERE tmpl_name = \"my_template\";";
$response = mysql_query( $select_data, $cnx );

//now print it out for the user.
if ( $one_line_of_data = mysql_fetch_array( $response ) ) {
extract ( $one_line_of_data );
}

$file = $_POST['file'];
$page_title   = $_POST['page_title'];
$image   = $_POST['image'];
$mtext   = $_POST['mtext'];
$text2   = $_POST['text2'];
$text3   = $_POST['text3'];

if (file_exists($dir . $file)) {
   echo "<center><p /><p class=\"NormalBold\">Success!<p /><p />";
} else {
   echo "The file $file does not exist";
}

$filename = "$file";

//Update the table in MySQL
    $update_data = "UPDATE cms_pages SET page_title = '$page_title', image =
'$image', mtext = '$mtext', text2 = '$text2', text3 = '$text2' WHERE
filename = '$file'";
    $response = mysql_query( $update_data, $cnx );
    if(mysql_error()) die ('database error<br>'. mysql_error());
    
    //Begining of Template Construction

      $mtext = nl2br($mtext);
      $text2 = nl2br($text2);
      $text3 = nl2br($text3);
      
//include "content.php"; This works with an external page included, but I
would like it to be in the database for easy changes.

// Is the file writable?
if (is_writable($dir. $filename)) {


   if (!$handle = fopen($dir . $filename, 'w')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
  
   echo "<center><p /><p class=\"NormalText\">$filename has been
updated.</p><p /></center>";
  
   fclose($handle);

} else {
   echo "The file $filename is not writable";
}

include "includes/footer.php";

?> 
</html>






on 11/18/05 7:14 PM Lists (lists@xxxxxxxxxxx) wrote:

> <?
> $var = "time";
> $var2 = "clock";
> echo "$var$var2";
> //outputs timeclock
> 
> $two_vars = "$var$var2";
> echo "$two_vars";
> //outputs timeclock
> ?>
> 
> Why put two variables in one field?  But if you want to store them,
> do: "$var, $var2".  After pulling this back from the database,
> explode into an array at the comma, using list to call them var and
> var2.
> 
> On Nov 18, 2005, at 7:54 PM, Marquez Design wrote:
> 
>> Greetings.
>> 
>> Does anyone know how to do this?
>> 
>> I have,
>> 
>> $var
>> 
>> $var2
>> 
>> In a field called two_vars in a MySQL db.
>> 
>> I am calling the variables inside PHP document.
>> 
>> In that document I am saying:
>> 
>> $var = "time"
>> $var2 = "clock"
>> 
>> <!-- I do the query in MySQL here -->
>> 
>> echo "$two_vars";
>> 
>> But the what prints out is
>> 
>> $var
>> 
>> $var2
>> 
>> not "time" and "clock".  I know that is what is in the database,
>> but I want
>> it to replace the variables when printed in the PHP file.
>> 
>> Does this make sense to anyone? Does anyone know how to do this?
>> 
>> --
>> Steve
>> 
>> -- 
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>> 
> 
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux