2015-07-10 21 views
0

我有PHP脚本,它负责取消订阅通讯用户。请检查以下内容:我应该使用什么命令我的php取消订阅脚本开始工作

<?php 
    session_start(); 
    $without_login = 1; 
    include("includes/config.inc.php"); 
    if(!(isset($_REQUEST['email']) && $_REQUEST['email'] != '')) 
    { 
     header("location:".$basehref); 
     exit(0); 
    } 
    $meta_title = 'Unsubscribe - '.store_company_name; 
    $meta_desc = ''; 
    $meta_keyword = ''; 
    include("header.php"); 
?> 
<div class="content" itemscope itemtype="http://schema.org/WebPage"> 
     <div class="pnav" itemprop="breadcrumb"><a href="<?php echo $basehref;?>" title="Home">Home</a> &raquo; <span id="on1">Unsubscribe From Mailing List</span></div> 
      <section> 
      <div class="about"> 
      <h1 itemprop="about">Unsubscribe From Mailing List</h1> 
      <hr> 
      <div itemprop="description" id="static_desc"> 

       <form action="" method="post" name="form"> 
    <input type="hidden" name="unsubscribe_email" id="unsubscribe_email" value="<?php echo mysql_real_escape_string($_REQUEST['email']);?>" /> 
     <div class="story_left" style="min-height:200px;"><br /> 
     <?php 
       $error = 0; 
       $to = $_REQUEST['email']; 
       $encrypt_email = decode5t($to); 
       if($encrypt_email != '') 
       { 
        $check_url = mysql_query("select * from tb_member where `email` = '".$encrypt_email."' and newsletter = 1"); 
        if(mysql_num_rows($check_url) > 0) 
        { 
         $error = 1; 
        } 
        if($error == 0) 
        { 
         $check_url = mysql_query("select * from news_letters where `email` = '".$encrypt_email."'"); 
         if(mysql_num_rows($check_url) > 0) 
         { 
          $error = 1; 
         } 
        } 
       } 
       if($error == 0) 
       { 
        echo 'The unsubscribe link you have clicked is invalid. <br> <br /> <input type="button" onclick="window.location=\''.$basehref.'\';" value="Continue" title="Continue" style="float:left; margin-left:250px;" class="choose-btn1" name="submit" />'; 
       } 
       else 
       { 
       ?> 
        Please confirm your unsubscribe request from <?php echo store_company_name;?> newsletters by clicking on the "Unsubscribe" button below to remove your email address.<br /><br /> 
        <input type="button" class="ungo-btn choose-btn1" title="Unsubscribe" value="Unsubscribe" name="submit" style="float:left; margin-right:20px;" /> 
        <input type="button" onclick="window.location='<?php echo $basehref;?>';" value="Cancel" title="Cancel" style="float:left;" class="choose-btn1" name="cancel" /> 

       <?php 
       } 
      ?> 

</div> 
</form> 
      </div> 
      </div> 
      </section> 
     <div class="clear"></div> 
    </div> 
<?php 
    include("footer.php"); 
?> 

有人可以建议如何将命令放入链接开始取消订阅用户?我在下面使用,但没有成功。

<a href='http://www.xyz.co.uk/unsubscribe.php?email=$_REQUEST['email']'>UNSUBSCRIBE HERE</a> 
+2

如果可以的话,你应该[停止U唱'mysql_ *'函数](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。他们不再被维护,并[正式弃用](https://wiki.php.net/rfc/mysql_deprecation)。了解[准备](http://en.wikipedia.org/wiki/Prepared_statement)[声明](http://php.net/manual/en/pdo.prepared-statements.php),并考虑使用PDO ,[这真的不难](http://jayblanchard.net/demystifying_php_pdo.html)。 –

回答

1

我认为您的脚本不会取消订阅用户,因为没有mysql查询来更新数据库。

下面的代码表明用户需要点击提交按钮来处理数据,在你的情况下是取消订阅用户。

<input type="button" class="ungo-btn choose-btn1" title="Unsubscribe" 
value="Unsubscribe" name="submit" style="float:left; margin-right:20px;" /> 

然而,甚至在用户点击提交按钮,我不知道在哪里的数据被发送,因为表单的动作是“”,请参阅以下内容:

<form action="" method="post" name="form"> 

假设通讯= 1指的是用户订阅电子报,下面是一个简单的例子,其中的脚本将 更新数据库,并设置通讯= 0(混蛋通讯)

  $to = $_REQUEST['email'];                          
      $encrypt_email = decode5t($to);                     
      if($encrypt_email != '')                       
      {                            
       $check_url = mysql_query("select * from tb_member where `email` = '$encrypt_email' and newsletter = 1"); 
       if(mysql_num_rows($check_url) > 0)                   
       {   
         mysql_query("UPDATE tb_member set newsletter = '0' where `email` = '$encrypt_email' and newsletter = 1");                         
        $error = 1;                        
       }                           
       if($error == 0)                        
       {                           
        $check_url = mysql_query("select * from news_letters where `email` = '$encrypt_email'");    
        if(mysql_num_rows($check_url) > 0)                  
        {  
         mysql_query("UPDATE tb_member set newsletter = '0' where `email` = '$encrypt_email'");                         
         $error = 1;                       
        }                          
       }                           
      }                            
      if($error == 0)                         
      {                            
       echo "The unsubscribe link you have clicked is invalid";              
      }                                
相关问题