Hello. Iv made a mysql table and PHP files wich can
Add, Edit, View and Delete text and data from the mysql
table.
The problem is that when I try to view php scripts from the
mysql table from web the php code is shown as html text,
and the PHP tags are removed.
For example I would like to view PHP code with the
show_source on my webpages.
How do I do that ?
Below is my file that add text to the mysql table :
<?php
include("connect.php");
$id=$_GET['id'];
$title=$_POST['title'];
$content=$_POST['content'];
if(!$_POST) {
echo "<form method='post' action='add.php'>";
echo "<table width=670><td bgcolor=lightblue>Title</td></table><input type='text' size='93' name='title'><br>";
echo "<table width=670><td bgcolor=lightgreen>Content</td></table><textarea name='content' cols='81' rows='30'></textarea><br>";
echo "<input type='submit' value='Add'>";
echo "<input type='button' onclick='history.go(-1)' value='Cancel'>";
echo "</form>";
}
elseif(!$title || !$content) {
echo "<a href='#' onclick='history.go(-1)'>All fields are required!</a><br>";
}
else {
$sql = "INSERT INTO $table SET
title='$title',
content='$content'
";
$query = mysql_query($sql) or die(mysql_error());
echo "Post added<br>";
echo "<br><a href='index.php'>To mainpage</a>";
}
?>
Below is the page that view the entry :
<?php
include("connect.php");
$id=$_GET['id'];
$sql = "SELECT * FROM $table WHERE id='$id'";
$query = mysql_query($sql) or die(mysql_error());
$result = mysql_fetch_array($query);
$title = $result["title"];
$content = $result["content"];
echo "<a href='index.php'>To mainpage</a></p>";
echo "<table border=1 cellpadding=2 cellspacing=0 width=650>";
echo "<tr><td bgcolor=lightgreen>$title</td></tr>";
echo "<tr><td bgcolor=FFFFE0>$content</td></tr>";
echo "</table>";
?>