|
| Web Hosting Deals | Holiday Logo Design | Webcam Chat | Website Header Templates | Register domain | Search Engine Optimisation | Web Hosting |
|
|||||||
| PHP / Perl / Java / JavaScript / CGI Tutorials PHP / Perl / Java / JavaScript / CGI Tutorials Please do not use this Forum to advertise your site or to link to tutorials. |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
||||
|
The CMS (#5) PHP
Now i know i said i would post the delete news page and a few others, but i will wait till twomorrow to post the others.
So just the delete page at the moment! PHP Code:
Right then lets get into it :'( $id = $_GET['id']; $id2 = $_POST['id']; Gets the ID of the tutorial we are attempting to delete if($_POST['deny']) { - So this is what happens if they click "no" they don't want to del that news post. $path = "http://www.yourdomain.com/admin/admin.php"; header("Location: $path"); JESUS! - Somthing you actually need to change................ First time for everything.. Change "www.yourdomain.com" to your domain. } elseif($_POST['confirm']) { So this is if they click "Yes" they want to delete that news post. (how dare they!) $query = "DELETE FROM news WHERE ID = '$id2'"; - Delete the row on the variable $id2 (now you can see why we created $id and $id2) header("Refresh: 2; edit-news.php"); - After 2 seconds, reidrect to edit-news.php. -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ So there we are! Our delete-news.php Whoooaa! I am so going to bed now. lol, thanks lads, hope you enjoyed and learned! Base
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png PointServ.co.uk - One of the UK's cheapest webhosting companies. |
|
|||
|
Can you explain a little bit more about why there is the
PHP Code:
Im asking because ive tried working with this file several times and I keep getting the following error: Code:
Parse error: syntax error, unexpected $end in /home/chixor/public_html/freshstart/delete-news.php on line 43 Code:
<?php
session_start();
if($_SESSION[username]=="") {
Header("Location: login.php");
} else {
//The following PHP script deletes entries from your MySQL database..
//Connecting to the MySQL database
include("includes/header.php");
//Naming some variables here.
$id = $_GET['id'];
$id2 = $_POST['id'];
if($_POST['deny']) {
//We shall not delete the entry, my lord.
$path = "http://".$_SERVER['HTTP_HOST']."/edit.php";
header("Location: $path");
exit;
} elseif($_POST['confirm']) {
//We shall proceed to delete!
//Naming some variables here.
//The MySQl query. Deletes an entry from the database.
$query = "DELETE FROM news WHERE ID = '$id2'";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
echo "The entry has been deleted";
header("Refresh: 2; edit.php");
} else {
//OK, we've ID'd the thing, can we proceed Cap'n?
?>
<!-- Some tables for formatting and a form to confirm the deletion.-->
<table align="center">
<form action="delete.php" method="post">
<tr><td>Do you really want to delete this entry?</td></tr>
<tr><td><input type="hidden" name="id" value="<?php echo "$id"; ?>" /><input type="submit" name="confirm" value="Yes" /><input type="submit" name="deny" value="No" /></td></tr>
</form>
</table>
<?php
}
?>
|
|
|||
|
Quote:
like: not <?php echo "$id"; ?> but <?php echo $id; ?> and you should add one more } at the end though. and this: if($_SESSION[username]=="") { you could better make it this: if(!isset($_SESSION['logged'])) { and then great a session called logged, when the user logged in succesfully. This is more save Caus now if the $_SESSION['username'] containts weird shit, it also continue to the page. |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|