请原谅!下面的代码基本上是将文本插入到表中,然后我可以编辑显示文本区域中插入文本的文本作为值。问题是,当我尝试更新内容时,它会发布新内容而不是更新,所以我有2个帖子。
麻烦的查询似乎相互冲突。我尝试使用(if($_GET== ect }else{)
分隔这些但仍然做同样的事情。除了没有更新,一切正常。
任何想法
<?php
session_start();
include("header.php");
include("connect_db.php");
function protect($string)
{
$string = mysql_real_escape_string($string); $string = strip_tags($string);
$string = addslashes($string); return $string;
}
echo"
<style>
fieldset {
font-size:30px;
font-family:calibri;
border-radius: 10px;
padding: 5px;
width:220px;
}
textarea#user {
border: 2px solid #C0DFFF;
border-radius: 10px;
height: 475px;
width: 850px;
outline: none;
resize: none;
padding-left:15px;
padding-right:15px;
padding-top:10px;
padding-bottom:10px;
font-family: calibri;
font-size: 22px;
}
</style>
<table width='100%' border='0' height='80%'>
<tr>
<td width='25%' valign='top'>
";
include("user_sidebar.php");
echo"
</td>
<td width='75%' valign='top'>
</br>
";
if($_GET['cmd']=='edit')
{
if(!$_POST['submit'])
{
$result = mysql_query("SELECT * FROM user_blogs WHERE username='$username' AND id='$content_id'");
while($row = mysql_fetch_array($result))
{
echo"
<form method='POST' action='".htmlspecialchars($_SERVER["PHP_SELF"])."'>
<table border='0'><tr><td>
<input id='user_form' type='text' name='title' value='".$row['title']."'>
</td></tr>
<tr><td>
<textarea id='user' name='content'>".$row['content']."</textarea>
</td></tr>
<tr><td align='right'>
<input id='submit' type='submit' name='submit' value='post'>
</td></tr></table>
</form>";
}
}
else
{
$title = $_POST['title'];
$content = $_POST['content'];
$username = $_SESSION['username'];
$errors = array();
echo"
<form method='POST' action='".htmlspecialchars($_SERVER["PHP_SELF"])."'>
<table border='0'><tr><td>
";
if(!$title){
$errors[] = "1";
echo "<input id='user_form' type='text' name='title'><span class='Euser'><i> name your blog</i></span>"; } else { echo "<input id='user_form' type='text' name='title' value='".$title."'>"; }
echo"
</td></tr>
<tr><td>
";
if(!$content){
$errors[] = "1";
echo "<textarea id='user' name='content'>your blog must be at least 20 characters</textarea>";
} else { echo "
<textarea id='user' name='content'>".$content."</textarea>"; }
echo"
</td></tr>
<tr><td align='right'>
<input id='submit' type='submit' name='submit' value='post'>
</td></tr></table>
</form>";
if(count($errors) > 0){
echo"<span class='submit_error'>you have not completed your blog</span>";
}elseif($content=='your blog must be at least 20 characters'){ echo
"<span class='submit_error'>you have not entered any content</span>";
}else {
$content_id=$_GET['content_id'];
$username=$_SESSION['username'];
$sql2 = 'UPDATE user_blogs SET title="$title" AND content="$content" WHERE id="$content_id" AND username="$username"';
$res2 = mysql_query($sql2) or die(mysql_error());
echo"<span class='submit_successful'><b><i>".$title."</i></b> has been updated successfully</span>";}
}
}
else
{
if(!$_POST['submit'])
{
echo"
<form method='POST' action='".htmlspecialchars($_SERVER["PHP_SELF"])."'>
<table border='0'><tr><td>
<input id='user_form' type='text' name='title'>
</td></tr>
<tr><td>
<textarea id='user' name='content'></textarea>
</td></tr>
<tr><td align='right'>
<input id='submit' type='submit' name='submit' value='post'>
</td></tr></table>
</form>
";
}
else
{
$title = $_POST['title'];
$content = $_POST['content'];
$username = $_SESSION['username'];
$errors = array();
echo"
<form method='POST' action='".htmlspecialchars($_SERVER["PHP_SELF"])."'>
<table border='0'><tr><td>
";
if(!$title){
$errors[] = "1";
echo "<input id='user_form' type='text' name='title'><span class='Euser'><i> name your blog</i></span>"; } else { echo "<input id='user_form' type='text' name='title' value='".$title."'>"; }
echo"
</td></tr>
<tr><td>
";
if(!$content){
$errors[] = "1";
echo "<textarea id='user' name='content'>your blog must be at least 20 characters</textarea>";
} else { echo "
<textarea id='user' name='content'>".$content."</textarea>"; }
echo"
</td></tr>
<tr><td align='right'>
<input id='submit' type='submit' name='submit' value='post'>
</td></tr></table>
</form>";
if(count($errors) > 0){
echo"<span class='submit_error'>you have not completed your blog</span>";
}elseif($content=='your blog must be at least 20 characters'){ echo
"<span class='submit_error'>you have not entered any content</span>";
}else {
$sql2 = "INSERT INTO `user_blogs` (`title`,`content`,`username`,`date`,`time`)
VALUES ('".$title."','".$content."','".$username."', NOW(), UTC_TIMESTAMP())";
$res2 = mysql_query($sql2) or die(mysql_error());
echo"<span class='submit_successful'><b><i>".$title."</i></b> has been posted successfully</span>";}
}
}
echo"
</td>
</tr>
</table>";
include("footer.php"); ?>
答案 0 :(得分:0)
请检查变量$content_id
中的值是否正确。如果你得到了正确的,那么你必须拿一个隐藏的输入框,你必须将$content_id
作为一个值。
这样你就可以将$content_id
这个变量的值变成后期数据。