Index Problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gkwhitworth
Forum Commoner
Posts: 85
Joined: Tue Sep 05, 2006 8:28 pm
Location: Wasilla, Alaska

Index Problems

Post by gkwhitworth »

Ok, Ok, Ok, Ok. I know I have somewhat covered this topic and feyd gave me a script to fix the situation, but this is a little different. I have the following setup:

user fills out form -> confirmation page calculates estimated total and shows information to send -> then it is mailed using a php script.

Everything is working fine until I send the PHP script, it can't find the variables that were sent from the form, even though the confirmation page can view them using Sessions, is this not possible within a script. How would I go about sending these through a script. I saw on a guy's website about using hidden text fields, but is this the only way to do it? Seems kinda drawn out.

--
Greg
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If I understand you correctly, continue using sessions.
User avatar
gkwhitworth
Forum Commoner
Posts: 85
Joined: Tue Sep 05, 2006 8:28 pm
Location: Wasilla, Alaska

Post by gkwhitworth »

I think you miss understood my question...probably on a large part that I can't write that well.

If I understand you correctly, continue using sessions.
I am using sessions already, that is where the problem is occuring. I assumed that as long as the session is going I could retrieve those variables.

If you would like to test it out it is at:
http://www.gkwinspired.com/contact/web_new.php

Once Again:

User fills out form (Works) -> User Sees Estimate and can recalculate total (Works) -> User clicks submit button and I get the following errors:

Code: Select all

Notice: Undefined index: fname in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 3

Notice: Undefined index: lname in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 4

Notice: Undefined index: email in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 5

Notice: Undefined index: phone in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 6

Notice: Undefined index: address in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 7

Notice: Undefined index: city in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 8

Notice: Undefined index: state in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 9

Notice: Undefined index: zip in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 10

Notice: Undefined index: package in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 11

Notice: Undefined index: flash in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 17

Notice: Undefined index: phpForm in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 19

Notice: Undefined index: asp in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 27

Notice: Undefined index: cms in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 29

Notice: Undefined index: email in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 33

Notice: Undefined index: name in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 33

Notice: Undefined index: phone in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 33

Notice: Undefined index: contact in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 33

Notice: Undefined index: comments in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 33

Notice: Undefined variable: name in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 38

Notice: Undefined variable: contact in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 38

Notice: Undefined variable: comments in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 38

Notice: Undefined variable: name in D:\users\gkwinspired.com\scripts\sendmail_web.php on line 39
So I am assuming that the variables aren't being passed for some reason.

Here is the code in the email script, I am not posting any other code since the form works up until now:

Code: Select all

<?	session_start();
		
	$fname = $_POST['fname'];
			$lname = $_POST['lname'];
			$email = $_POST['email'];
			$phone = $_POST['phone'];
			$address = $_POST['address'];
			$city = $_POST['city'];
			$state = $_POST['state'];
			$zip = $_POST['zip'];
			$package = $_POST['package'];
			$packagePrices = array (
					'Basic' => 1500,
					'Professional Lite' => 2300,
					'Premium Professional' => 3500
					);												
			$flash = $_POST['flash'];
			$flashPrice = 500;
			$phpForm = $_POST['phpForm'];
			$phpPrices = array (
					'1' => 200,
					'2' => 400,
					'3' => 600,
					'4' => 800,
					'5' => 1000
					);
			$asp = $_POST['asp'];
			$aspPrice = 1500;
			$cms = $_POST['cms'];
			$cmsPrice = 3000;
	
	foreach( array('email','name','phone','contact','comments') as $feedback) {
		$_SESSION[$feedback] = $_REQUEST[$feedback];
		}
			
	mail("email@email.com", "Feedback Form Results" , "name: $name\nPhone: $phone\nContacting Who: $contact\nComments:\n$comments", 
		"From: $name <$email>");
		header ("Location: http://www.gkwinspired.com");		
?>
Thanks and any help is appreciated!

--
Greg
User avatar
gkwhitworth
Forum Commoner
Posts: 85
Joined: Tue Sep 05, 2006 8:28 pm
Location: Wasilla, Alaska

I figured it OUT!!

Post by gkwhitworth »

Ok, what was happening was the session was beginning on the first page and then the second page called up the variables, but my email script was trying to recreate the variables into an array that starts a session....when a session was already created. All the script needed to consist of was:

Code: Select all

<?	session_start();
	header ("Location: http://www.gkwinspired.com");		
	ini_set("SMTP","0.0.0.0");
	
       	mail("email@domain.com", "Web Order Results" , "name: $fname $lname\nPhone: $phone\nEmail: $email\n
       	Address: $address\nCity: $city\nState: $state\nZip: $zip\nPackage: $package\nFlash: $flash\n PHP Forms: $phpForm\n
       	ASP: $asp\n CMS: $cms\n", 
		"From: $fname $lname <$email>");
		
?>
Nothing else, since everything else was already set. Huh, (*sigh of relief*), feels nice to accomplish something on my own. Thanks though.

--
Greg
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Didn't we cover this in another topic? You cannot just throw your POST/GET vars into vars without checking something. If there is no form posted, then you are going to get uninitialized variable notices all over the place. If you are using sessions, on page one start the session and load the form. On the second page, start the session, capture the posted data and read them into the sessions. On all subsequent pages, start your session and reference your session vars, checking if they are set before assigning them into variables or checking against there value.
Post Reply