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
  #1 (permalink)  
Old 03-09-10, 06:59 PM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
My PHP Code Is Not Working Correctly Can Anyone Help?

Hi,
I hope that you all are having agreat day. I am looking for some help getting this php code to wrk for me properly. Maybe someone here can help me as I am a novice to any type of coding. I am often in need ofa helping hand.

The code that I am showing here is supposed to redirect the user to a certain web page (salesletters) of three different ones or one default page if they should choose the "other" option .

1. After being shown a question to answer the user clicks on one of option A.) option B.) or option C.) from a pull down menu or enter some information into a "other" box.

2. The user clicks on a submit button that sends their information, (name, email) to my autoresponder.

3.The autoreponder then redirects the user to my main.php page where my php code is supposed to choose and show the correct page for the selection the user has chosen. It is also supposed to personalize this page by adding the users first name to this page.

The problem that I am having is that the only page out of the 4 that I can get to show is the default page (other option page) no matter what selection is chosen A.) B.) or C.) The default page "other" always displays. I would like to know if it is the .php code that is to blame or maybe some other problem in my set up. Here is the code on my main.php:

PHP Code:

<?

session_start
();
$name=$_REQUEST["name"];
$other=$_REQUEST["other"];



$mainquestion=$_REQUEST["mainquestion"];
$today=time();
$today=date("Y-m-d",$today);
$ip=$_SERVER["REMOTE_ADDR"];

$letterused=$mainquestion;
session_register("letterused");
$campused=$campaign;
session_register("campused");

If (!
$_COOKIE["name"] AND !$_REQUEST["name"])
{

$root=$_SERVER["DOCUMENT_ROOT"];
include(
"$root/cn/letters/salesletter.html");
exit;
}

If(isset(
$_COOKIE["name"]))
{
If(!isset(
$_REQUEST["name"]))
{
$name=$_COOKIE["name"];
$mainquestion=$_COOKIE["mainquestion"];
}
}



If(isset(
$_REQUEST["name"]))
{
$firstname=$_REQUEST["name"];
setcookie("name",$firstname,time()+3600); 
$mainquestion=$_REQUEST["mainquestion"];
setcookie("mainquestion",$mainquestion,time()+3600);


}





If(
$other<>"")
{
$fieldname="other";
$mainquestion="other";
}


$root=$_SERVER["DOCUMENT_ROOT"];
$input 
file("$root/cn/letters/$mainquestion.html"); 

foreach (
$input as $line) { 

$line str_replace("[name]"$name$line); 

echo 
$line;
}


# time to include the dbconnect



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

If(isset(
$_REQUEST["mainquestion"]))
{

$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','$_REQUEST[other]')";
$result2=mysql_query($sql2);
}


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

$allwordcount=count($allotherwords);

$x="0";
while(
$x<$allwordcount)
{
If(
$length<>"0")
{

$sql3="Insert into isl_allwords (campid,word) values ('1','$allotherwords[$x]')";
}

$result3=mysql_query($sql3);
$x++;
}
// checking if there was a submission or not
?>
I know this is a lot but I am hoping some one here will understand it
Any help will be greatly appreciated.

Thank You.
Tony S.
Reply With Quote
  #2 (permalink)  
Old 03-10-10, 02:30 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
The $_REQUEST array includes cookies.

PHP: $_REQUEST - Manual

PHP: Description of core php.ini directives - Manual

I think the best approach would be to put some echo commands in to show you how the logic is running.

For example:

PHP Code:

echo 'Tested for request<br />'
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
Tony S. (03-12-10)
  #3 (permalink)  
Old 03-10-10, 05:18 PM
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 very much for your response and help. I am sad to say that I do not know php coding at all. I think I need more help. :-( Because thae $_REQUEST array includes cookies is this the reson that the code is not working propely. So where in the code would I put the echo commands and what should I then expect or look for?

Thanks Again,
Tony S.
Reply With Quote
  #4 (permalink)  
Old 03-10-10, 05:31 PM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
I also looked at the referrences that you included. Now know how rewally limeted I am. Could you please help me further to unerstand what I need to do to get this code to work properly? I would be truly greatful.

Tony S.
Reply With Quote
  #5 (permalink)  
Old 03-10-10, 09:03 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'm not sure exactly what you are trying to do, or what the form that submits to this script looks like. I tried to clean it up to repair a few problems, but it may not work on the first try. I would run this script while keeping the original as a backup.

PHP Code:

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

//not using session, and session_register is depreciated as well.
// $letterused=$mainquestion;
// session_register("letterused");
// $campused=$campaign;
// session_register("campused");

If (!$_COOKIE["name"] AND !$_REQUEST["name"])
{

$root=$_SERVER["DOCUMENT_ROOT"];
include(
"$root/cn/letters/salesletter.html");
exit;
}

// If(isset($_COOKIE["name"]))
// {
// If(!isset($_REQUEST["name"]))
// {
// $name=$_COOKIE["name"];
// $mainquestion=$_COOKIE["mainquestion"];
// }
// }

setcookie("name",$name,time()+3600); 
setcookie("mainquestion",$mainquestion,time()+3600); 

//if $other is empty.
if($other == "") {
$fieldname="other";
$mainquestion="other";
}

//$root is already declared.
// $root=$_SERVER["DOCUMENT_ROOT"];
$input file("$root/cn/letters/$mainquestion.html"); 

foreach (
$input as $line) { 

$line str_replace("[name]"$name$line); 

echo 
$line;
}


# time to include the dbconnect



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

if(isset(
$mainquestion) && $mainquestion != '')
{

$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);

$x=0;
while(
$x<$allwordcount)
{
if(
$length == "0")
{

$sql3="Insert into isl_allwords (campid,word) values ('1','$allotherwords[$x]')";
}

$result3=mysql_query($sql3);
$x++;
}
// checking if there was a submission or not
?>
Reply With Quote
The Following User Says Thank You to Jcbones For This Useful Post:
Tony S. (03-12-10)
  #6 (permalink)  
Old 03-10-10, 09:44 PM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
I want to thank you Jcbones for your help. The people here have been absolutely oustanding in the help that they provide. I only hope that i will be able to return the help to someone else in need one day. Thank you again for your help I will try the edited code and let yo know what happens.

Best Regards,
Tony S.
Reply With Quote
  #7 (permalink)  
Old 03-11-10, 10:54 AM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
Jcbones, I tried the revised php code and there has been no change in how it preforms. I am beginning to think that it must be something more than the php code causing the program not to run properly. If you or any one else here has any other ideas or advice it is welcome. Thank you so much again for your time, effort and help.

Best Regards,
Tony S.
Reply With Quote
  #8 (permalink)  
Old 03-11-10, 05:19 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
This is my take on this script. You need to edit the switch function, or you can post your submission script here, and I will edit it in for you.

I did away with the cookies, and used a session instead. Any more help will require you to post your file contents that contains the form.

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($mainquestion) {
    case 
'page1':
        
$file 'page1.html';
        break;
    case 
'page2':
        
$file 'page2.html';
        break;
    case 
'page3':
        
$file 'page3.html';
        break;
    default:
        
$file 'default.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);
    }

?>
Reply With Quote
The Following User Says Thank You to Jcbones For This Useful Post:
Tony S. (03-12-10)
  #9 (permalink)  
Old 03-11-10, 06:07 PM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
Jcbones, I am very greatful to you for the time you have put into this project. I can't thank you enough. i have a question. Would my submission script be my user opt-in page where the "main question" is found? or would it be my "letters folder" where my three salesletters plus the default sales letter is located? How this program is set up is that all of my .php pages(admin.php, paging.php, salesletterbuilderaweber.php. etc.) plus 2 folders Images, and letters. In the letters folder are my 3 salesletters plus the default. My main.php where the code you are helping me with is located in the main website root directory. Do you think that the way this is set up will have any bearing on how the script is performining?

In any case I should put in the names of my .html salesletters?
Reply With Quote
  #10 (permalink)  
Old 03-11-10, 06:17 PM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
I am including my opt-in form page .html. I hope this helps.
Code:
</head>
<body background="sasonlineback.png" bgcolor="#e13926" (16).jpg="">
<table border="8" cellspacing="0" cellpadding="0" width="800" align="center">
<tbody>
<tr>
<td valign="undefined" align="undefined"><img title="" alt="" width="800" height="500" src="../../images/sasonlinebusinesslogo.jpg"></td></tr></tbody></table><br>
<table border="8" cellspacing="0" cellpadding="12" width="800" align="center">
<tbody>
<tr>
<td class=" wproHighlight" bgcolor="#999999" valign="undefined" align="undefined">
<p align="center"><big><big><font size="6"><font color="#0000cc"><font face="Arial"><strong>SAS Online Business Success Is A Host Of Online Businesses That Can Help You With All Of Your Online Home Business Help From Start To Finish!</strong>&nbsp;<br>
</font></font></font><br>
</big></big><font color="#ffffff" face="Arial"></font><font face="Arial">
<p align="center">
<table style="width: 500px; border-collapse: collapse" border="1" cellspacing="0" bordercolor="#000000" cellpadding="10" bgcolor="#0066ff" align="center">
<tbody>
<tr valign="top">
<td width="100%">
<p align="center">
<form method="post" action="http://www.aweber.com/scripts/addlead.pl">
<p align="center"><strong><font color="#ff0000" size="5">GET FREE INTERNET MARKETING NEWSLETTER</font></strong></p>
<p><strong>For More Infomation&nbsp; and to&nbsp;<font color="#000000">get your free monthly internet marketing newsletter full of <u>useful tips</u>, <u>interesting information</u> and <u>online home business help topics</u>&nbsp; </font></strong><font color="#000000"><font color="#ffffff">Sign Up </font><u><em><strong><font color="#cc0000">Now!</font></strong></em></u></font></p>
<p align="center">Please Enter Your Name And Primary&nbsp; Email&nbsp; Address Below</p>
<p align="center"><font size="2" face="Verdana"><font size="3">First Name:</font><br>
<input name="name">
<p align="center"><font size="3">Email:<br>
</font><input name="from">
<p align="center"><font size="3"><strong>What Kind of Help Are You Looking for With Your Online Home Business?</strong> </font></font>
<p align="center"><select name="mainquestion">
<option selected="selected" value="business">Help Starting Your Online Home Business?</option>
<option value="products">Getting Hot Digital Products For Online Business Help or Sales of 100% Profit?</option>
<option value="affiliates">Help With Affiliates Or Affiliate Marketing Projects</option></select></p>
<p><input value="1" type="hidden" name="campaign"> <input value="mainquestion" type="hidden" name="fieldname">
<p align="center"><font size="2" face="Verdana"><font size="3">If Other, please specify</font>:</font><br>
<p align="center"><textarea rows="10" cols="40" name="other"></textarea>&nbsp;</p>
<p align="center"><input value="905977818" type="hidden" name="meta_web_form_id"> <input type="hidden" name="meta_split_id"> <input value="conversionninja" type="hidden" name="listname"> <input value="http://www.sasonlinebusinesssuccess.com/main.php" type="hidden" name="redirect">
<p align="center"><font color="#ffffff">SAS Online Business Success&nbsp; values your privacy</font></p>
<p align="center"><font color="#ffffff">Your information&nbsp; will be held&nbsp; totally confidential</font></p>
<p align="center"><input value="submit" type="submit" name?submit?>&nbsp;</td></tr></tbody></table>
<p align="center"></font>
<p align="center"><big><big><font face="Arial">When You Need Help As We All Do... Please Turn To SAS Online Business Success!!!</font></big></big></p>
<p align="center"><big><big><font size="3"><a title="" target="_blank" href="../../Privacy.html"><font color="#000000">Privacy</font></a><font color="#000000">&nbsp;| </font><a title="" target="_blank" href="../../sasonlinebusinesssuccessdisclaimer.html"><font color="#000000">Disclaimer</font></a><font color="#000000"> | </font><a title="" target="_blank" href="../../TermsOfUse.html"><font color="#000000">Terms Of Use</font></a></font></big></big></p></td></tr></tbody></table><br>
<div align="center"></div></form>
</body>
</html>
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 05:32 AM
Require Forum website project code in php language suaveshiva PHP 4 04-30-07 03:21 PM
PHP code formatter... jumbo1 The Lounge 1 03-19-07 12:01 PM
Can anyone help me ? (problem using php variables in html db insert code) chronic_ PHP 2 06-13-04 11:19 AM
How to sale php code to customer without giving him code pradeep_soft PHP 4 03-12-04 12:10 PM


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