error in unsubscribe.php script

This is a discussion on "error in unsubscribe.php script" within the PHP Forum section. This forum, and the thread "error in unsubscribe.php script are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 18th, 2007, 10:20
Up'n'Coming Member
Join Date: Jul 2006
Location: manila
Age: 28
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
error in unsubscribe.php script

i have this code below unsubscribe php script in which it occurs an error wen i run the script, please could any one help me solve this script.. thanks

error: Fatal error: Call to undefined function: delete_mail() in /home/simply22/public_html/test/mailing/unsubscribe.php on line 14

Code: Select all
<?
    require('inc/config.php');

    if ($_SERVER['REQUEST_METHOD'] == "POST") {

        delete_mail("POST");
    }
    if ($_SERVER['REQUEST_METHOD'] == "GET") {
        if ($_GET['email'] == "") {
           include('inc/form2.php');
        } else {
           delete_mail("GET"); ---> in this line coz the error
        }
    }

?>
Reply With Quote

  #2 (permalink)  
Old Jul 18th, 2007, 11:16
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: error in unsubscribe.php script

There is no delete_mail function in PHP, but you can define your own - either via the include file that's called in at the top of your script, or within your own script if you prefer.
Reply With Quote
  #3 (permalink)  
Old Jul 18th, 2007, 13:01
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: error in unsubscribe.php script

I think your looking for the unset() function. e.g.

PHP: Select all

<?
    
require('inc/config.php');

    if (
$_SERVER['REQUEST_METHOD'] == "POST") {

        unset(
$_POST);
    }
    if (
$_SERVER['REQUEST_METHOD'] == "GET") {
        if (
$_GET['email'] == "") {
           include(
'inc/form2.php');
        } else {
           unset(
$_GET);
        }
    }

?>
Reply With Quote
  #4 (permalink)  
Old Jul 18th, 2007, 15:43
Up'n'Coming Member
Join Date: Jul 2006
Location: manila
Age: 28
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: error in unsubscribe.php script

i use the unset function but it doesn't work here is the other code below for the function delete_mail()

Code: Select all
<?
function delete_mail() {

    $email = $_POST['email'];

    if ($email == "") {
       $email = $_GET['email'];
    }

    $sql2="select * from mail where email='$email'";
    $result2=mysql_query($sql2) or die("select  fails");
    $no=mysql_num_rows($result2);

    if ($no==0) {
       echo "Your email was not found in the list: " . LISTNAME;
    } else {
       echo "Your email was unsubscribed from the list: " . LISTNAME;
    }

    $sql2="delete from mail where email='$email'";
    $result2=mysql_query($sql2) or die("unsubscribe failed, please try again");

    }
}

?>
Reply With Quote
  #5 (permalink)  
Old Jul 18th, 2007, 18:42
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: error in unsubscribe.php script

I think I've seen the problem.
You called a function, specifying text as a parameter.
Also, in your function you failed make reference to the parameter, so nothing would have been passed to the function to delete.

PHP: Select all

<?php

    
require('inc/config.php');

    if (
$_SERVER['REQUEST_METHOD'] == "POST") {

        
delete_mail("$_POST[email]");
// Before it was just "POST"

    
}
    if (
$_SERVER['REQUEST_METHOD'] == "GET") {
        if (
$_GET['email'] == "") {
           include(
'inc/form2.php');
        } else {
           
delete_mail("$_GET[email]");
// before it was just GET
        
}
    }

?>
Notice that you are sending parameters, so we need to accommodate them in the function.

i.e.
PHP: Select all

<?php

function delete_mail($email) {

      
$sql2="select * from mail where email='$email'";
    
$result2=mysql_query($sql2) or die("select  fails");
    
$no=mysql_num_rows($result2);

    if (
$no==0) {
       echo 
"Your email was not found in the list: " LISTNAME;
    } else {

    
$sql2="DELETE * FROM mail WHERE email='$email'";
    
$result2 mysql_query($sql2) or die("unsubscribe failed, please try again");

       echo 
"Your email was unsubscribed from the list: " LISTNAME;

    }

   
}

?>
Hopefully that should work.

Last edited by balaclave; Jul 19th, 2007 at 23:02. Reason: Fixing code.
Reply With Quote
  #6 (permalink)  
Old Jul 19th, 2007, 17:30
Junior Member
Join Date: Mar 2007
Location: California
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: error in unsubscribe.php script

Balaclave has the better practice on handling this situation.. instead of calling the value from the $_POST pass it right to the function. But just for CSUN's information that since his function doesn't take any parameters (originally) from the way it looks he could have solved the problem by passing nothing.




delete_mail();

<?
function delete_mail() {

$email = $_POST['email']; //gets the value


################################################## #############
# if ($email == "") { #
# $email = $_GET['email']; //is this line even needed? #
# if you don't get a value from the $_POST (since i would #
# assume you are posting this form, should this be an error #
# Handler instead?) just a thought, #
# #
# If ($_POST['email'] != "" || NULL){ #
# do something #
# } #
# else { #
# Display error. #
# } #
# #
################################################## #############


$sql2="select * from mail where email='$email'";
$result2=mysql_query($sql2) or die("select fails");
$no=mysql_num_rows($result2);

if ($no==0) {
echo "Your email was not found in the list: " . LISTNAME;
} else {
echo "Your email was unsubscribed from the list: " . LISTNAME;
}

$sql2="delete from mail where email='$email'";
$result2=mysql_query($sql2) or die("unsubscribe failed, please try again");

}
}

?>



However as i said Bala has the right idea about the proper format, though i am unsure if just passing "$_POST" and "$_GET" will do what you want, your going to want to pass the email address it self. So you would probably rather pass: delete_mail($_POST['email']); i could be wrong.

Last edited by dnhdevelopment; Jul 19th, 2007 at 17:34.
Reply With Quote
  #7 (permalink)  
Old Jul 19th, 2007, 22:49
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: error in unsubscribe.php script

Quote:
So you would probably rather pass: delete_mail($_POST['email']); i could be wrong.
Yeh, you're right.
Except you can't have apostrophes in the $_GET or $_POST so you just have to use delete_mail($_GET[email]);

So some working code would be:
PHP: Select all

   <?php
    
require('inc/config.php');

    if (
$_SERVER['REQUEST_METHOD'] == "POST") {

        
delete_mail("$_POST[email]");
// Before it was just "POST"

    
}
    if (
$_SERVER['REQUEST_METHOD'] == "GET") {
        if (
$_GET['email'] == "") {
           include(
'inc/form2.php');
        } else {
           
delete_mail("$_GET[email]");
// before it was just GET
        
}
    }

?>
And the function:
PHP: Select all

   <?php
function delete_mail($email) {

      
$sql2="select * from mail where email='$email'";
    
$result2=mysql_query($sql2) or die("select  fails");
    
$no=mysql_num_rows($result2);

    if (
$no==0) {
       echo 
"Your email was not found in the list: " LISTNAME;
    } 
    else {

    
$sql2="DELETE * FROM mail WHERE email='$email'";
    
$result2=mysql_query($sql2) or die("unsubscribe failed, please try again");

       echo 
"Your email was unsubscribed from the list: " LISTNAME;
    }


}

?>
Somehow an extraneous } got in my function code so it's now removed.

Last edited by balaclave; Jul 19th, 2007 at 22:59.
Reply With Quote
  #8 (permalink)  
Old Jul 23rd, 2007, 17:56
Junior Member
Join Date: Mar 2007
Location: California
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: error in unsubscribe.php script

good catch. Bad habit of mine. so used to doing a

Code: Select all
document.getElementById('****');
and unless we hear otherwise from the original poster.

*ding* Next!
Reply With Quote
Reply

Tags
unsubscribephp

Thread Tools

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
members php script error csun PHP Forum 2 Jul 4th, 2007 06:46
Ie Script error acrikey Starting Out 2 Mar 26th, 2007 14:22
PHP Forgot password script error eddie PHP Forum 4 Mar 4th, 2007 15:43
Another ASP script error message a.jenery Classic ASP 13 Apr 21st, 2006 01:10
Php error when run script jj1234 PHP Forum 3 Feb 17th, 2006 13:27


All times are GMT. The time now is 20:56.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43