Current location: Hot Scripts Forums » Programming Languages » PHP » My PHP Code Is Not Working Correctly Can Anyone Help?


My PHP Code Is Not Working Correctly Can Anyone Help?

Reply
  #11 (permalink)  
Old 03-11-10, 08:55 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
I don't think you need sessions or cookies here, or an autoresponder.

Use the mail function PHP: mail - Manual to send an email, then redirect with this:

PHP Code:

$nextpage=$_POST['mainquestion'].'.php';

if (
is_file($next_page)) header('location:'.$next_page);
else 
header('location:main.php'); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
Tony S. (03-12-10)
  #12 (permalink)  
Old 03-12-10, 12:46 AM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
wirehopper, thank you for your response, The reason that I use a autoresponder is mainly to keep track of how my campain is doing. Track statistics for my future referrence. :-)

Respectfully,
Tony S.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #13 (permalink)  
Old 03-12-10, 10:41 AM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
Hi Jcbones, I hope you are doing well.
I am confused again. In the "CASE" string should I put the page name in both areas: case 'page1':
$file = 'page1.html';
Or only after "case"?
Also how will the code be able to define what salesleter (page) to call for the different main question options?

Will this portion of the code need a actual filename?:
if(empty($other)) {
$fieldname="other"; //I do not know what fieldname is, as it isn't passed or declared.
$mainquestion="other";

I apologise for so many questions. my coding skills are close to 0
Tony S.

Last edited by Tony S.; 03-12-10 at 10:44 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #14 (permalink)  
Old 03-12-10, 04:20 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
I think WireHopper is right.

But,

PHP Code:

<?php
//don't really need the next line as you are not using sessions.
session_start();
$name = (isset($_SESSION['name'])) ? $_SESSION['name'] : NULL;
$name = (isset($_POST['name'])) ? $_POST['name'] : $name;
$other = (isset($_SESSION['other'])) ? $_SESSION['other'] : NULL;
$other = (isset($_POST['other'])) ? strip_tags($_POST['other']) : $other;
$mainquestion = (isset($_SESSION['mainquestion'])) ? $_SESSION['mainquestion'] : NULL;
$mainquestion = (isset($_POST['mainquestion'])) ? $_POST['mainquestion'] : $mainquestion;
$today=time();
$today=date("Y-m-d",$today);
$ip=$_SERVER["REMOTE_ADDR"];
$root=$_SERVER["DOCUMENT_ROOT"];

If (
$name == NULL) {
include(
"$root/cn/letters/salesletter.html");
exit;
}

$_SESSION['name'] = $name;
$_SESSION['other'] = $other;
$_SESSION['mainquestion'] = $mainquestion;

if(empty(
$other)) {
$fieldname="other"//I do not know what fieldname is, as it isn't passed or declared.
$mainquestion="other";
}

//REPLACE THE "CASE" STRING WITH THE NAME OF YOUR SCRIPTS.
//switch is used for sanitation so someone cannot access files they are not suppose to.

/* SWITCH SANITATION
* pass variable $mainquestion
* if the variable matches a case,
* That block of code will run.
* If it doesn't match a case, 
* Then the default block of code will
* run.
*/
switch($mainquestion) {
    case 
'business':
        
$file 'business.html';
        break;
    case 
'products':
        
$file 'products.html';
        break;
    case 
'affiliates':
        
$file 'affiliates.html';
        break;
    default:
        
$file 'other.html';
}

$input file_get_contents("$root/cn/letters/$file"); 

echo 
str_replace("[name]"$name$input); 

include(
"$root/cn/settings.inc.php");
dbconnect();

if(
$mainquestion != NULL) {
    
$sql="INSERT INTO `isl_statistics` (`campid`,`optionname`,`fieldname`,`date`,`IP`) Values ('1','$mainquestion','mainquestion','$today','$ip')";
    
$result=mysql_query($sql);

    
$length=strlen($other);

    
    if(
$length 0)
    {
    
$sql2="INSERT INTO `isl_othertrack` (`campid`,`optionname`,`userresponse`) Values ('1','mainquestion','$other')";
    
$result2=mysql_query($sql2);
    }


    
$allotherwords=explode(" ",$other);

    
$allwordcount=count($allotherwords);
    if(
$allwordcount 0) {
        
$sql 'INSERT INTO `isl_allwords`(`campid`,`word`) VALUES ';
        for(
$x 0$x <= $allwordcount$x++) {            
            
$thisvalue $allotherwords[$x];
            
$values[] = "('1','$thisvalue')";            
        }
        
$value implode(',',$values);
        
$result3=mysql_query($sql.$value);
    }

?>
I'm wondering how you are sending the $_POST variables from the perl script, or if you are.

I would set the action on the form to my php script, and then use the page like this:
*Note* email validation done with php-email-address-validation - Project Hosting on Google Code

PHP Code:

<?php
//don't really need the next line as you are not using sessions.
session_start();
$name = (isset($_SESSION['name'])) ? $_SESSION['name'] : NULL;
$name = (isset($_POST['name'])) ? $_POST['name'] : $name;
$from = (isset($_POST['from'])) ? $_POST['from'] : NULL;
$other = (isset($_SESSION['other'])) ? $_SESSION['other'] : NULL;
$other = (isset($_POST['other'])) ? strip_tags($_POST['other']) : $other;
$mainquestion = (isset($_SESSION['mainquestion'])) ? $_SESSION['mainquestion'] : NULL;
$mainquestion = (isset($_POST['mainquestion'])) ? $_POST['mainquestion'] : $mainquestion;
$today=time();
$today=date("Y-m-d",$today);
$ip=$_SERVER["REMOTE_ADDR"];
$root=$_SERVER["DOCUMENT_ROOT"];

If (
$name == NULL) {
include(
"$root/cn/letters/salesletter.html");
exit;
}

$_SESSION['name'] = $name;
$_SESSION['other'] = $other;
$_SESSION['mainquestion'] = $mainquestion;

if(empty(
$other)) {
$fieldname="other"//I do not know what fieldname is, as it isn't passed or declared.
$mainquestion="other";
}

include(
'validator.php');
$mail = new EmailAddressValidator;
$subject 'Thanks for your request.';
$message 'This is the message to be sent in the email.';
$email $from;
$headers  'MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
$headers .= 'From:Wbste <publicrelations@mysite.com>'"\r\n";

if(
$mail->check_email_address($email)) {
 if(
mail($email,$subject,$message,$headers)) echo "Mail sent to $email!";
 else echo 
"Mail sent to $email failed!";
}
else {
 echo 
'You did not specify a valid email address.';
}
//REPLACE THE "CASE" STRING WITH THE NAME OF YOUR SCRIPTS.
//switch is used for sanitation so someone cannot access files they are not suppose to.

/* SWITCH SANITATION
* pass variable $mainquestion
* if the variable matches a case,
* That block of code will run.
* If it doesn't match a case, 
* Then the default block of code will
* run.
*/
switch($mainquestion) {
    case 
'business':
        
$file 'business.html';
        break;
    case 
'products':
        
$file 'products.html';
        break;
    case 
'affiliates':
        
$file 'affiliates.html';
        break;
    default:
        
$file 'other.html';
}

$input file_get_contents("$root/cn/letters/$file"); 

echo 
str_replace("[name]"$name$input); 

include(
"$root/cn/settings.inc.php");
dbconnect();

if(
$mainquestion != NULL) {
    
$sql="INSERT INTO `isl_statistics` (`campid`,`optionname`,`fieldname`,`date`,`IP`) Values ('1','$mainquestion','mainquestion','$today','$ip')";
    
$result=mysql_query($sql);

    
$length=strlen($other);

    
    if(
$length 0)
    {
    
$sql2="INSERT INTO `isl_othertrack` (`campid`,`optionname`,`userresponse`) Values ('1','mainquestion','$other')";
    
$result2=mysql_query($sql2);
    }


    
$allotherwords=explode(" ",$other);

    
$allwordcount=count($allotherwords);
    if(
$allwordcount 0) {
        
$sql 'INSERT INTO `isl_allwords`(`campid`,`word`) VALUES ';
        for(
$x 0$x <= $allwordcount$x++) {            
            
$thisvalue $allotherwords[$x];
            
$values[] = "('1','$thisvalue')";            
        }
        
$value implode(',',$values);
        
$result3=mysql_query($sql.$value);
    }

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to Jcbones For This Useful Post:
Tony S. (03-12-10)
  #15 (permalink)  
Old 03-12-10, 04:50 PM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
Jcbones thank you and wirehopper both for your considerable help with this coding problem. As I stated before my php coding knowledge is very limeted. It seems the more help tha i get the more confused I get. It will take me some time to digest the information that you have given me then intergrate it into my program. You have been very helpful and i will get back to you on how the revisions have worked out. Again I want to thank you for your assistance. Your help is welcome as well as appreciated.

Best Regards,
Tony S.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #16 (permalink)  
Old 03-12-10, 07:30 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
It might help you to reduce the task down and focus on each element until it all works.

Start with the form that lets them send an email and then redirects.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
Tony S. (03-12-10)
  #17 (permalink)  
Old 03-12-10, 07:46 PM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
wirehopper, That is great advice, Sometimes things seem a little overwhelming. It wouyld seem best to approach it differenyly. In this case one element at a time as opposed to trying to figure it all out in one big project. Thank you for your help, I will definitely use your advice. :-)

Best Regards
Tony S.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Image Gallery showing headers and code slaterino PHP 0 08-08-08 06:32 AM
Require Forum website project code in php language suaveshiva PHP 4 04-30-07 04:21 PM
PHP code formatter... jumbo1 The Lounge 1 03-19-07 01:01 PM
Can anyone help me ? (problem using php variables in html db insert code) chronic_ PHP 2 06-13-04 12:19 PM
How to sale php code to customer without giving him code pradeep_soft PHP 4 03-12-04 01:10 PM


All times are GMT -5. The time now is 10:32 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.