I have a class that contains 2 functions one for removing post and one for submitting post. The function for submitting the post will redirect to any page I want just fine and if it is the same page it will be displayed with the new post.
The function used for removing the post will refresh or redirect but if it’s redirected back to the same page the page does not appear updated until the page is refreshed again (a second time). I have looked and haven’t found anything that works or a reason why this is happening. I’m new to php so go easy on me!
Is the page reloading before it know the post has been deleted? What can I do to solve this?
Here is my code:
class userPost{
// For Removing Post
function remove(){
if(($_SERVER['REQUEST_METHOD'] == "POST") && ($_POST['delete_id'])){
if(!$_POST['delete_id'] || !$_SESSION['SESS_USER']){
header('Location: ?id=profile');
}
else{
$delete = mysql_real_escape_string($_POST['delete_id']);
$remove = mysql_query("DELETE FROM Post WHERE post_id = '".$delete."' AND post_member='" . $_SESSION['SESS_USER'] . "'");
if($remove){
header('Location: ?id=profile');
}
elseif(!$remove){ ?>
<script>
$('#div-id').triggerevent(function(){
$('#div-id').html(newContent);
});
</script>
<?php
} // End Else
} // End Else
} // End If
} // End If
} // End Class
You need an
exit;afterheader. Otherwise PHP continues to process the script.As an aside: Don’t continue programming this way. There are so many issues with this script I wouldn’t know where to start. A good book to learn PHP the right way is PHP : Ojects, Patterns, and Practices by Matt Zandstra.