open file, passing variable data, and insert into a db
Posted: Sat Jun 26, 2010 9:03 am
Hi,
I think this is the most common method to pass variable data into html tags and then insert this html into the database, below is an abstract of the method in a class (I'm using OOP),
The issue is, I have very long html page needs to be passed it into the database, and I don't want to put the long html tags into my class's method, bcos this html file is just a template which will be changed from time to time. so ideally I will put the html code above into an external - template.php so that I will need to update this template only without messing around too much in my class method. and the most important thing in this template is, I want to pass some variable data into it, such as above.
I tried include() like this,
but it shows the value of '1' in my database which is very strange.
So I tried file_get_contents(),
it then won't pass any variables into it. it will shows this in the database - $this -> database -> real_escape_string($params['first_name']),instead of the information.
it would be great if you have any ideas.
Many thanks,
Lau
I think this is the most common method to pass variable data into html tags and then insert this html into the database, below is an abstract of the method in a class (I'm using OOP),
Code: Select all
$content = '
<table>
<tr><td>
<p>Dear '.$this -> database -> real_escape_string($params['first_name']).',</p>
<p>Thank you for your order....</p>
<td>
</tr>
</table>';
$content = "'".$this -> database -> real_escape_string($content)."'";
$sql = " INSERT INTO invoices (content) VALUES($content)"
$result = $this -> database -> query($sql);I tried include() like this,
Code: Select all
$content = include 'template.php';So I tried file_get_contents(),
Code: Select all
$content = file_get_contents('template.php');it would be great if you have any ideas.
Many thanks,
Lau