Re: Problem with function

From: Date: Fri, 12 Sep 2008 12:44:58 +0000
Subject: Re: Problem with function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-279968@lists.php.net to get a copy of this message
Jason Pruim schreef:
So, I am fighting with a problem function... I have used this function on a previous project and it worked just fine, so I'm not sure what changed... The only difference is that on this site, I'm using mod_rewrite to write all non-existent folder requests into a php file to process what to do with it.
so no difference in php versions, etc etc. check phpinfo() output for the current error_reporting/display_errors settings. and learn about error_log() and how to 'tail' the error log (fuck knows how you go about that on windows ... then there are reasons I have a Mac ;-))
here's some code: processing file: <?PHP
    require("php.ini.php");
    require("dbmysqliconnect.php");
    require("defaults.php");
    require("notify_email.php");
the echo '10'; occurs when you include notify_email.php, the other echos only when you call the function in that file.
    $link = dbmysqliconnect($server, $username, $password, $database, $link);
can you output anything after this line? chances are you don't have mysqli
    $date = time();
    
    //Do NOT insert or update sales rep database through this method... Only included to be supplied to the notify_email function. JP
    $salesRepID = $_POST['txtSalesRepID'];
    $Record= $_POST['txtRecord'];
my guess is you never reach this line.
    notify_email($Record, $salesRepID);
    $stmt = mysqli_stmt_init($link);
        //Create the statement
    mysqli_stmt_prepare($stmt, "UPDATE purl.schreur SET
                        FName = ?,
                        LName = ?,
                        email = ?,
                        phone = ?,
                        record = ?,
                        subscribed = ?,
                        date = ?,
                        IPAddress = ?,
                        Business = ?,
                        Address1 = ?,
                        City = ?,
                        State = ?,
                        Zip = ?,
                        Coffee = ?,
                        Meeting = ?,
                        time = ?")
    or die("prepare error " . mysqli_error($link));
    mysqli_stmt_bind_param($stmt, 'ssssssssssssssss',
                           $_POST['txtFName'],
                           $_POST['txtLName'],
                           $_POST['txtEmail'],
                           $_POST['txtPhone'],
                           $_POST['record'],
                           $_POST['subscribed'],
                           $date,
                           $_SERVER['REMOTE_ADDR'],
                           $_POST['txtBusiness'],
                           $_POST['txtAddress1'],
                           $_POST['txtCity'],
                           $_POST['txtState'],
                           $_POST['txtZip'],
                           $_POST['rdoCoffee'],
                           $_POST['rdoTime'],
                           $_POST['areaPlans'])
    or die( "bind error " . mysqli_error($link));
//Add the record
    mysqli_stmt_execute($stmt) or die( "execute error " . mysqli_error($link));
        ?>
notify_email.php file: <?PHP
        function notify_email($Record, $salesRepID) {
        require("defaults.php");
        require("func.sendemail.php");
        require("dbmysqliconnect.php");
        $salesRep = array(1 => "tim@schreurprinting.com, jpruim@schreurprinting.com", 2 => "richardc@schreurprinting.com, jpruim@schreurprinting.com", 3 =>"jpruim@schreurprinting.com", 4=>"japruim@raoset.com");
        echo "1";
        $link1 = dbmysqliconnect($server, $username, $password, $database, $link);
    echo "2";
        $sql = "SELECT * FROM schreur WHERE record='{$Record}'";
        $row[] = mysqli_query($link1, $sql) or die("Could not perform query: ".mysqli_errno($link1));
    echo "3";
        $result = $row[0];
        echo "4";
           //    $dataSet = array();
           //    while ($row = mysqli_fetch_assoc($result)) {
//echo "<br>while<BR>";
//            $dataSet[] = $row;
    //        }
        $from= "No-Reply@schreurprinting.com";
        echo "5";
        $returnPath = "no-reply@schreurprinting.com";
        $replyTo = "no-reply@schreurprinting.com";
        echo $Record;
        echo "6";
    //    echo "<br>Just before while in notify_email.php<br>";
               //    echo "<br>directly above while<br>";
           //    echo "<BR>dataset print: ";
    //    print_r($dataSet);
    //    echo "<BR>";
    //    echo "<br>directly above foreach<br>";
            //foreach ( $dataSet AS $row ) {
        echo "6";
        while ($row = mysqli_fetch_assoc($result)) {               echo "inside while";
            //Build the e-mail headers
            $ID = $row['salesRep'];
            $to = $salesRep[$ID];
            $headers = "From: ".$from."\n";
            $headers .= "Return-Path: ".$returnPath."\n";
            $headers .= "Reply-To: ".$replyTo."\n";
                   $subject = "{$row['FName']} wants coffee!";
                       $message = "First Name: {$row['FName']} \n";
            $message .= "Last Name: {$row['LName']}\n";
            $message .= "Company " . $row['Business'] . "\n";
            $message .= "Email:" .$row['email'] . "\n";
            $message .= "Phone: " .$row['phone'] . "\n";
            $message .= "Address: " . $row['Address1'] . "\n";
            $message .= "City: " . $row['City'] . "\n";
            $message .= "State: " .$row['State'] . "\n";
            $message .= "Zip: ". $row['Zip'] . "\n";
            $message .= "Coffee of choice: ".$row['Coffee'] . "\n\n";
            $message .= "When a good time would be: \n".$row['Meeting'] . "\n\n";
            $message .= "Current plans: \n\n";
            $message .= $row['plans'] . "\n\n";
                send_email($to, $subject, $message, $headers);
                   }
echo "7";
        echo <<<PRE
        <pre>
    Headers: $headers
    To: $to
    Subject: $subject
    Message:
        $message
        </pre>
PRE; echo "8";
        echo "Just after end of while in notify_email.php";
        //    header("Location: index.php");
        echo "9";
    } //Function closed
    echo "10";
?> yes all of the echo's in there are for testing purposes to see where it's choking. Ever since I started using mod_rewrite, I seem to have lost my error reporting from php so if someone knows a trick on how to fix that I would appreciate it :) On my page when I load it, all I see is the "10" I echo at the end of the notify_email function. I think I'm having another dense moment and it will be something simple but I have looked over the code for the past day with no break throughs.... So ANY help is greatly appreciated, and comes with a beverage of choice if you can make it to where I am! :)
consider posting example code that is a little more succinct, it also helps *you* if you take the time to write test code that strips everything not directly related to the problem it's usually easier to find it.

« previous php.general (#279968) next »