I have a basic CMS for some news articles, basically some of my content contains links as the
<a href=""></a>
html so that the links are added when written to the page. Could this be why my content is being randomly duplicated? when edited?
Here's the php I'm using to edit.
include'includes/connection.php';
$pName = $_POST['pName'];
$pItem = $_POST['pItem'];
$pCategory = $_POST['pCategory'];
$pDate = $_POST['pDate'];
$pAuthor = $_POST['pAuthor'];
$pContent = $_POST['pContent'];
$Page = $_POST['Page'];
$id = $_POST['id'];
$pApproval = $_POST['pApproval'];
$pPriority = $_POST['pPriority'];
$pImage_Name = $_POST['pImage_Name'];
if($pItem != 2){
$updateq = "UPDATE sitecontent SET ID = '$pID', Post_Title = '$pName', Post_Year = '$pCategory', Date = '$pDate', Post_Author = '$pAuthor', Post_Content = '$pContent', Page = '$Page', Post_Approval = '$pApproval', Priority = '$pPriority', Image_Name = '$pImage_Name' WHERE ID = '$_POST[id]'";
$result = mysql_query($updateq) or die (mysql_error());
header("Location:admin.php");
}
if($pCategory = 2){
$updateq = "UPDATE reviews SET review_id = '$pID', review_title = '$pName', review_category = '$pCategory', review_content = '$pContent', review_image = '$piName', review_approval = '$pApproval' WHERE ID = '$_POST[id]'";
$result = mysql_query($updateq) or die (mysql_error());
header("Location:reviews-category.php");
}
This is the page before that sends the data.
<form action="editp.php" method="POST" name="editform">
<table cellpadding="10" >
<tr>
<td width="86" valign="top" >
<label for="pName" style="padding:10px; ">Post Title</label></td>
<td width="550">
<input type="text" name="pName" style=" width:550px;border:#000099; margin:10px;" value="<?php echo $post['Post_Title']; ?>"/>
</td>
</tr>
<tr>
<td width="86" valign="top" >
<label for="pCategory" style="padding:10px; ">Category</label></td>
<td width="550">
<input type="text" name="pCategory" style=" width:50px;border:#000099; margin:10px;" value="<?php echo $post['Post_Year']; ?>"/>
</td>
</tr>
<tr>
<td>
<label for="pItem" style="padding:10px;">Item Type</label>
</td>
<td>
<select name="pItem" style="border:#000099; margin:10px;">
<option value="1">News</option>
<option value="2">Review</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="pName" style="padding:10px;">Article ID</label>
</td>
<td>
<input type="text" name="pID" style="border:#000099; margin:10px;" value="<?php echo $post['ID']; ?>"/>
</td>
</tr>
<tr>
<td>
<label for="pName" style="padding:10px;">Post Date</label>
</td>
<td>
<input type="text" name="pDate" style="border:#000099; margin:10px;" value="<?php echo $post['Date']; ?>">
</td>
</tr>
<td>
<label for="pName" style="padding:10px;">Post Author</label>
</td>
<td>
<input type="text" name="pAuthor" style="border:#000099; margin:10px;" value="<?php echo $post['Post_Author']; ?>"/>
</td>
</tr>
<tr>
<td>
<label for="pName" style="padding:10px;">Home Page</label>
</td>
<td>
<select name="Page" style="border:#000099; margin:10px;">
<option value="0">None</option>
<option value="1">Home</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="pPriority" style="padding:10px;">Home Priority</label>
</td>
<td>
<select name="pPriority" style="border:#000099; margin:10px;">
<option value="0">None</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="pName" style="padding:10px;">Post Content</label>
</td>
<td>
<textarea style="width:550px; height:200px;border:#000099; margin:10px;" type="text" name="pContent" id="pContent" value="<?php echo $post['Post_Content']; ?>"><?php echo $post['Post_Content']; ?></textarea>
</td>
</tr>
<tr>
<td>
</td>
<td style="padding:10px;">
<span id="btnStrong" style=" padding: 2px 8px;background-color:#C00;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#FFF; cursor:pointer;">Bold</span>
<span id="btnItalic" style=" padding: 2px 8px; background-color:#C00;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#FFF; cursor:pointer;">Italic</span>
<span id="btnPara" style=" padding: 2px 8px; background-color:#C00;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#FFF; cursor:pointer; margin-left:10px;">Paragraph</span>
<span id="btnBreak" style=" padding: 2px 8px; background-color:#C00;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#FFF; cursor:pointer; margin-left:10px;">Line Break</span>
<span id="btnLink" style=" padding: 2px 8px;background-color:#C00;font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; color:#FFF; cursor:pointer;">Link</span>
</td>
</tr>
<td>
<label for="pImage_Name" style="padding:10px;">Image Name</label>
</td>
<td>
<input type="text" name="pImage_Name" style="border:#000099; margin:10px; width:550px;" value="<?php echo $post['Image_Name']; ?>"/>
</td>
</tr>
<tr>
<td>
<label for="pApproval" style="padding:10px;">Approval</label>
</td>
<td>
<select name="pApproval" style="border:#000099; margin:10px;">
<option value="0">Pending</option>
<option value="1">Approved</option>
</select>
</td>
</tr>
<tr align="right">
<td><input type="hidden" name="id" value="<?php echo $_GET['id']; ?>"/></td>
<td colspan="2"><span style="margin-left:10px;">Please check the changes above before submitting</span><br/>
<input type="submit" name="go" value="Submit Changes" style=" padding: 2px 8px;background-color:#C00; color:#FFF; margin:10px;"/>
</td>
</tr>
</table>
</form>
Are you sure you want if($pCategory = 2){
and not: if($pCategory == 2){
?
Your if($pCategory = 2){
will always evaluate to true, hence the duplicates.
Your UPDATE is potentially changing the ID of the post
SET ID = '$pID'
I cannot see where $pID
is set in your code, but I bet it's not the same as $_POST[id]
.
You do assign $id = $_POST['id'];
Perhaps you meant to assign to $pID
rather than to $id
?
Either way, I would not include setting the ID in your UPDATE at all. No upside, and risks introducing errors.
chown
provided the correct solution (+1), but I think my input is correct and valuable, too - Eric J. 2012-04-03 21:57