Web Hosting Deals Holiday Logo Design Webcam Chat Website Header Templates Register domain Search Engine Optimisation Web Hosting
Go Back   Talk Mania Forum > Tutorials > PHP / Perl / Java / JavaScript / CGI Tutorials

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.

 Image
Buy Sell Downloads

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-31-2007, 08:04 AM
Base's Avatar
Senior Member
 
Join Date: Mar 2007
Location: North Yorkshire, UK
Posts: 121
Base is on a distinguished road
Send a message via MSN to Base Send a message via Skype™ to Base
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:
<?php
session_start
();
if(
$login_username=="") {
Header("Location: login.php");
} else {
//The following PHP script deletes entries from your MySQL database..
//Connecting to the MySQL database
include("../includes/connect.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
}
?>

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.
Reply With Quote
  #2 (permalink)  
Old 04-24-2007, 05:21 AM
Junior Member
 
Join Date: Apr 2007
Posts: 4
chixor1 is on a distinguished road
Can you explain a little bit more about why there is the
PHP Code:
<? php ?>
at the end?

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
I have only made 2 changes so far to your file for this, here is my code:

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
}
?>
Reply With Quote
  #3 (permalink)  
Old 05-19-2007, 02:20 PM
Junior Member
 
Join Date: May 2007
Location: Croatia
Posts: 20
Jabba is on a distinguished road
Send a message via MSN to Jabba
thankssss!
Reply With Quote
  #4 (permalink)  
Old 05-19-2007, 11:47 PM
Junior Member
 
Join Date: May 2007
Posts: 7
alain is on a distinguished road
Good Job !
Reply With Quote
  #5 (permalink)  
Old 05-20-2007, 01:32 AM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
Quote:
Originally Posted by chixor1 View Post
Can you explain a little bit more about why there is the
PHP Code:
<? php ?>
at the end?

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
I have only made 2 changes so far to your file for this, here is my code:

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
}
?>
you only did the right changes XD with the session vars, so should work... Btw, put all variables out of the " and "...
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.
Reply With Quote
  #6 (permalink)  
Old 05-20-2007, 10:52 AM
Junior Member
 
Join Date: May 2007
Posts: 18
boyscout is on a distinguished road
Nice code!
Reply With Quote
  #7 (permalink)  
Old 05-20-2007, 11:06 AM
Junior Member
 
Join Date: May 2007
Posts: 20
janrunejohansen is on a distinguished road
Quote:
Originally Posted by boyscout View Post
Nice code!
Have to Agree!
Reply With Quote
  #8 (permalink)  
Old 05-20-2007, 11:30 AM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
nice code, only found some bugs for you to repair XD and hold variables out of the " and ", for rest, good job, will maybe try it when I have time
Reply With Quote
  #9 (permalink)  
Old 06-06-2007, 04:30 PM
Junior Member
 
Join Date: Jun 2007
Posts: 24
shami is on a distinguished road
Send a message via MSN to shami Send a message via Yahoo to shami
nice dudw

esasy work to do here
Reply With Quote
  #10 (permalink)  
Old 06-06-2007, 11:16 PM
puresea's Avatar
Junior Member
 
Join Date: Feb 2007
Posts: 3
puresea is on a distinguished road
Thanks a lot for these tutorials, Base. They've been really helpful thus far.

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +2. The time now is 03:05 AM.


Fake ID

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC8
Forums Copyright © Talk-Mania.com