<?php
//Open connection to the database
mysql_connect("localhost", "phpuser", "sesame") or die("Failure to communicate with database");
mysql_select_db("test");
if($_post['submit']=='submit')
{
//Format the data
$comment_id=$_post['comment_id'];
$comment_header=$_post['comment_header'];
$as_comment_header=addslashes($comment_header);
$comment=$_post['comment'];
$as_comment=addslashes($_post['comment']);
//Update values
$query="update comments set comment_header='as_comment_header', comment='$as_comment' where id=$comment_id";
$result=mysql_query($query);
if(mysql_affected_rows()==1)
{
$succes_msg='<p>Your comment has been updated.</p>';
}
else{
error_log(mysql_error());
$succes_msg='<p>Something went wrong.</p>';
}
}
else{
//Get the comment header and comment
$comment_id=$_get['comment_id'];
$query="select comment_header, comment from comments where id=$comment_id";
$result=mysql_query($query);
$comment_arr=mysql_fetch_array($result);
$comment_header=stripslashes($comment_arr[0]);
$comment=stripslashes($comment_arr[1]);
}
$thispage=$_server['php_self'];
//have to do this for heredoc
$form_page=<<<EOFORMPAGE
<style type="text/css">
<!--
body, p{
color:black; font-family:verdana; font-size:10pt}
h1{
color:black; font-family:arial; font-size:12pt}
-->
</style>
</head>
<body>
<table border=0 cellpadding=10 width=100%>
<tr>
<td bgcolor="#F0F8FF" align=center valign=top width=17%>
</td>
<td bgcolor="#FFFFFF" align=center valign=top width=83%>
<h1>Comment edit</h1>
$succes_msg
<form method="post" action="$thispage">
<input type="text" size="40" name="comment_header" value="$comment_header">
<br>
<br>
<textarea name="comment" rows=10 cols=50>$comment</textarea>
<br>
<br>
<input type="hidden" name="comment_id" value="$comment_id">
<input type="submit" name="submit" value="Submit">
</form>
</td>
</tr>
</table>
</body>
</html>
EOFORMPAGE;
echo $form_page;
?>