So I'm trying to get a little script running, and I'm beating my head against a wall. I should mention at this point that I'm a PHP newbie.
PHP 4.3
MySQL 4.0.13
This is a page of the script on which you can edit a string of HTML stored in a MySQL database, then when you hit "update" the DB field is updated and the page refreshes to display the new info.
The problem is, it's not displaying the info in the DB accurately, and the problem cascades when you repeatedly hit "update."
For a piece of test code I'm using one of my category recip tables. The code is stored in the DB accurately, but when it displays on the page it's missing the first line of code and there's an extra "> at the end that isn't in the database. When you hit "update" and the page refreshes, THAT's when the first line of code and ending "> appear in the DB, and then I lose one more line of code at the top and get one more "> at the end of the code.
When I "view source" on the page when first going to it (when the code is fresh from the DB) the first line of code is actually in the page source but not displayed on the page, and the extra "> is also in the source.
I'm sure this is something stupid that should be staring me in the face. Please help, losing my fuckin' mind here. Code is below.
PHP Code:
<?php
//Edit HTML Code
//For Admin Control Panel
// HANDLE POST METHOD
if (isset($_POST['submit'])) {
// Include File With Connection To Database
include ("inc/connect.inc");
// Insert New Code Info Into Database
$new_code = $_POST['new_code'];
$new_code = addslashes($new_code);
$query = "UPDATE site SET template='$new_code' WHERE siteid=1";
mysql_query($query);
// Disconnect from Database
include ("inc/disconnect.inc");
echo "HTML Template Successfully Edited<BR><BR><BR>";
}
?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Edit Reciprocal Link Template - Recip Philes</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
// POPULATE FORM WITH DB INFO
// connect to mysql and select database
include ("inc/connect.inc");
// pull info from database and assign variable to query
$pullinfo = "SELECT template FROM site WHERE siteid=1";
$result = mysql_query($pullinfo);
?>
<form action="edit-recip-template.php" method="POST" >
<p>EDIT HTML Template In Database</p>
<p> </p>
<table width="676" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="533"> </td>
</tr>
<tr>
<td width="533">
<textarea name="new_code" rows=30 cols=70
value="<?php while ($info_to_edit = mysql_fetch_object($result)) {
$oldcode = $info_to_edit->recip_template;
echo $oldcode;
}
?>">
</textarea>
</td>
</tr>
<tr>
<td width="533">
<input type="submit" name="submit" value="Update Code">
</td>
</tr>
</table>
</form>
<?php
// Disconnect from Database
include ("inc/disconnect.inc");
?>
</body>
</html>