Mit HTML-area fungerer ikke, hvad gør jeg galt?
Godaften..Jeg har prøvet at implementere HTML-area til en lille side med database for at afprøve det.. Det virker tilsyneladende fint nok med implementeringsdelen.. Dog gemmer det ikke i databasen som jeg vil have det til.. Siden kan ses her: http://www.valuable.dk/praccalot_htmlarea/
Når man trykker på redigerknappen ude til højre hiver den godt nok HTML-area menuen frem og ligeledes indholdet fra databasen, men når man ændrer i det og trykker på rediger knappen nulstiller den blot hele den aktuelle række i tabellen :/ I kan selv afprøve siden, hvis i ikke forstår hvad jeg mener..
Spørgsmålet er så, hvor ligger fejlen/fejlene og hvordan får jeg det til at virke som planlagt?
Koden til de tre relevante sider kommer her:
-------------------------------------------------
/// pracc.edit.php ///
-------------------------------------------------
<html>
<head>
<title>HTML-area testing</title>
<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = "htmlarea/"; // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera') >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
document.write(' language="Javascript1.2"></scr' + 'ipt>');
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script>
</head>
<body>
<center>
<br><br><br><br><br>
<?php
include_once('inc.config.php');
mysql_connect($cfg['mysql']['host'],$cfg['mysql']['username'],$cfg['mysql']['password']);
mysql_select_db($cfg['mysql']['database']);
$query = mysql_query("SELECT * FROM lans2 WHERE id=".$_GET['id']."") or die(mysql_error());
$row = mysql_fetch_assoc($query);
?>
<script language="JavaScript1.2" defer>
editor_generate('test');
</script>
<form method="post" action="form.handle.php">
<?
echo $row['author'];
?>
<input type="hidden" name="referer" value="edit_lans2">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
<input type="hidden" name="offset" value="<?php echo $_GET['offset']; ?>">
<textarea name="test" rows="6" cols="80" onfocus="[test]">
<?php echo $row['title']; ?>
</textarea>
<br>
<input type="submit" value="rediger">
</form>
<?php
include_once('inc.config.php');
mysql_connect($cfg['mysql']['host'],$cfg['mysql']['username'],$cfg['mysql']['password']);
mysql_select_db($cfg['mysql']['database']);
$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
$total = mysql_result(mysql_query("SELECT COUNT(*) FROM lans2"),0);
$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
$start_point = ($offset-($cfg['pages_each_way']*$cfg['limit']) < 0) ? 0 : $offset-($cfg['pages_each_way']*$cfg['limit']);
$end_point = ($offset+($cfg['pages_each_way']*$cfg['limit']) > $total) ? $total : $offset+($cfg['pages_each_way']*$cfg['limit']);
$page_number = ($start_point/$cfg['limit'])+1;
if (isset($_GET['deleteID'])) {
mysql_query("DELETE FROM lans2 WHERE id=".$_GET['deleteID']."") or die(mysql_error());
}
$query = mysql_query("SELECT * FROM lans2 ORDER BY id ASC LIMIT ".$offset.",".$cfg['limit']."") or die(mysql_error());
while ($row = mysql_fetch_assoc($query)) {
echo '<center><table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">';
echo '<tr><td width="120" height="40"><center><font face="Verdana" style="font-size: 8pt"><b> ';
echo $row['author'].'';
echo '</b></td>';
echo '<td width="600"><font face="Verdana" style="font-size: 8pt"> ';
echo $row['title'].'';
echo '</td><td width="30"><center>';
echo '<a href="pracc.edit.php?offset='.$offset.'&id='.$row['id'].'"><img src="edit.gif" border="0" width="12" height="13"></a>';
echo '</td></tr></table>';
}
?>
</body>
</html>
-------------------------------------------------
/// form.handle.php ///
-------------------------------------------------
<?php
include('inc.config.php');
mysql_connect($cfg['mysql']['host'],$cfg['mysql']['username'],$cfg['mysql']['password']);
mysql_select_db($cfg['mysql']['database']);
if ($_POST['referer'] == 'post_lans2') {
if ($_FILES['image']['name'] != '') {
$image = time().substr($_FILES['image']['name'],strrpos($_FILES['image']['name'],'.'));
move_uploaded_file($_FILES['image']['tmp_name'], '../files/'.$image);
} elseif ($_POST['standard'] != '') {
$image = $_POST['standard'];
} else {
$image = '';
}
mysql_query("INSERT INTO lans2 VALUES ('','".$_POST['title']."','".$_POST['author']."',now(),'".$_POST['synopsis']."','".$_POST['text']."','".$image."')") or die(mysql_error());
header("Location: index.php");
}
if ($_POST['referer'] == 'edit_lans2') {
mysql_query("UPDATE lans2 SET title='".$_POST['title']."', author='".$_POST['author']."', synopsis='".$_POST['synopsis']."', text='".$_POST['text']."', image='".$_POST['image']."' WHERE id=".$_POST['id']."") or die(mysql_error());
header("Location: index.php");
}
?>
-------------------------------------------------
/// index.php ///
-------------------------------------------------
<html>
<head>
<title>HTML-area testing</title>
</head>
<body>
<center>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<?php
include_once('inc.config.php');
mysql_connect($cfg['mysql']['host'],$cfg['mysql']['username'],$cfg['mysql']['password']);
mysql_select_db($cfg['mysql']['database']);
$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
$total = mysql_result(mysql_query("SELECT COUNT(*) FROM lans2"),0);
$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
$start_point = ($offset-($cfg['pages_each_way']*$cfg['limit']) < 0) ? 0 : $offset-($cfg['pages_each_way']*$cfg['limit']);
$end_point = ($offset+($cfg['pages_each_way']*$cfg['limit']) > $total) ? $total : $offset+($cfg['pages_each_way']*$cfg['limit']);
$page_number = ($start_point/$cfg['limit'])+1;
if (isset($_GET['deleteID'])) {
mysql_query("DELETE FROM lans2 WHERE id=".$_GET['deleteID']."") or die(mysql_error());
}
$query = mysql_query("SELECT * FROM lans2 ORDER BY id ASC LIMIT ".$offset.",".$cfg['limit']."") or die(mysql_error());
while ($row = mysql_fetch_assoc($query)) {
echo '<center><table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">';
echo '<tr><td width="120" height="40"><center><font face="Verdana" style="font-size: 8pt"><b> ';
echo $row['author'].'';
echo '</b></td>';
echo '<td width="600"><font face="Verdana" style="font-size: 8pt"> ';
echo $row['title'].'';
echo '</td><td width="30"><center>';
echo '<a href="pracc.edit.php?offset='.$offset.'&id='.$row['id'].'"><img src="edit.gif" border="0" width="12" height="13"></a>';
echo '</td></tr></table>';
}
?>
</body>
</html>