2013-05-13 44 views
-4

我的PHP脚本是在前端向数据库中的成员输入一些新信息时发送的,用于发送电子邮件和短信。然而,电子邮件代码和SMS代码单独运行,但是当放在一起代码不会被执行。我的程序跳过了PHP中的一个函数

实际上跳过的代码。我试图在被调用函数中做出故意的错误,但它没有认出它。为什么?

<?php 
    error_reporting(E_ALL^E_NOTICE); 

    define('INCLUDE_CHECK', true); 

    require 'functions.php'; 
    include ("generatesms.php"); 
    include ("class.phpmailer.php"); 
    include ("../sendsmsV3.5/sendsmsV3.5/CurlProcess.php"); 
    include ("../sendsmsV3.5/sendsmsV3.5/Way2Sms.php"); 
    include ("class.smtp.php"); 

    // The above files can be included only if INCLUDE_CHECK is defined 
    $host  = "localhost"; // Host name 
    $username = "root";  // Mysql username 
    $password = "";   // Mysql password 
    $db_name = "test";  // Database name 
    $tbl_name = "mails";  // Table name 

    // Connect to server and select database. 
    mysql_connect($host, $username, $password) or die("cannot connect"); 
    mysql_select_db($db_name)or die("cannot select DB"); 

    // Get values from form 
    $subject = $_POST['subject']; 
    $email = $_POST['email']; 
    $phone = $_POST['phone']; 
    //$dept = $_POST['dept']; 
    $content = $_POST['content']; 
    $month = $_POST['birthday-mm']; 
    $day  = $_POST['birthday-dd']; 
    $year  = $_POST['birthday-yyyy']; 
    $date_eve = "$year-$month-$day"; 
    $dept  = $_POST['branch']; 

    if (empty($dept)) { 
     echo("You didn't select any DEPEARTMENTS."); 
    } else { 
     $N = count($dept); 

     for($i=0; $i < $N; $i++) { 
      echo $dept[$i]; echo "<br>"; 
      $dep = $dept[$i]; 

      // Insert data into mysql 
      $sql = "INSERT INTO $tbl_name(subject, body, dept, phone, email, date_eve) VALUES ('$subject', '$content', '$dep', '$phone', '$email', '$date_eve')"; 

      $result = mysql_query($sql); 

      // if successfully insert data into database, displays message "Successful". 
      if ($result) { 
       echo "Successful"; 
       echo "<BR>"; 
       newssender($dept, $content, $subject); 
       generatesms($dept,$date_eve,$subject); 

       echo "<a href='index.php'>Back to main page</a>"; 
      } else { 
       echo "ERROR"; 
      } 
     } 
    } 

    // close connection 
    mysql_close(); 
+0

你有一些代码给我们看? – 2013-05-13 16:42:30

+0

如果没有看到代码,我们无法回答。你可以编辑它到你的问题? – andrewsi 2013-05-13 16:42:33

+0

确定....我在猜谜游戏.... – itachi 2013-05-13 16:46:04

回答

0

首先,你对所有的SQL都有很大的问题。您不应该使用mysql_ *函数,因为它们已被弃用,并且您不会对输入进行清理,从而使您暴露于漏洞之中。 (http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php

如果你能提出你的newssender()功能的代码,我可以给你一个详细/具体的答案,但在此期间,我会给通过一些调试过程中供其他用户进入一个通用的解决方案。

,如果你有这样的代码:

myFunction1(); 
myFunction2(); 

myFunction1()运行,但myFunction2()是不是,你可以尝试注释掉// myFunction1()(这听起来像你这样),在这一点上,如果myFunction2()运行那么很明显该问题驻留在myFunction1()。以下是要寻找的东西:

  1. 致命错误。确保您打开错误和通知以在您的代码中查找语法或其他错误
  2. 查找可能存在于您的代码中的任何dieexit。那些脚本结束,不再执行代码。

一个快速的方法来测试#2是做到这一点:

myFunction1(); 
echo 'I made it here!'; 

如果您没有看到“我在这里做了!”在屏幕上那么明显的代码没有走到这一步,这意味着结束的代码之前从myFunction1()

返回我希望帮助!