Jump to content
Killersites Forums

Variables not displaying after collecting form info


arcanepsyche
 Share

Recommended Posts

Hello,

 

I am very new to PHP and have been watching Stefan's videos in an attempt to learn. I'm doing well, except that I'm stuck on getting collecting information to display on the .php page that is processing the form results.

 

When I submit the form, everything loads fine in terms of text and html code, but the variables I have set up using the $_post information are just being skipped.

 

I'm certain the php is collecting the form info because I used $_get and the information showed up in the URL bar, it just didn't display on the page.

 

Here is the code: (changed back to $_post)

 

<?php

 

$_post['name_first'];

$_post['name_last'];

$_post['email_address'];

$_post['comment'];

 

$name_first=$_post['name_first'];

$name_last=$_post['name_last'];

$email=$_post['email_address'];

$comments=$_post['comment'];

 

print "The first name is: {$name_first}

";

 

print "The last name is: {$name_last}

";

 

print "The email address is: {$email}

";

 

print "And the comments are: {$comments}

";

 

?>

 

 

Any help for a beginner is appreciated!

Link to comment
Share on other sites

Thanks for the help, it's good to know I don't need that code.

 

However, I'm still getting the same result.

 

Here is the code after deleting the portion you told me to:

 

<?php

 

$name_first=$_post['name_first'];

$name_last=$_post['name_last'];

$email=$_post['email_address'];

$comments=$_post['comment'];

 

print "The first name is: {$name_first}

";

 

print "The last name is: {$name_last}

";

 

print "The email address is: {$email}

";

 

print "And the comments are: {$comments}

";

 

?>

 

 

I'm still not getting any of the form information to display.

 

I'm not sure if this matters, but I've created my form in Serif's Webplus10 and then set the form element names in that program. Then, I set it to use a remote scripts from my hard drive and it uploads both the page and my scripts to my existing hosting account. Would Webplus somehow be the problem?

 

Here is a link to a page I just created with a test form set to submit to my .php page. Not sure if that's helpful either though: www.cornerstonewebsolutions.com/page10.html

 

I've checked the names of the form elements over and over to make sure they match, so I know it doesn't have to do with that.

 

Thanks again,

Zac

Edited by arcanepsyche
Link to comment
Share on other sites

jbwebdesign, you can see the form code on the link that was posted.

 

That's really strange, everything looks correct. And when I use Tamper Data to view the request being sent, the variables are being POSTed properly - so it must be a problem on the receiving page.

 

Two things I can suggest though it shouldn't make any difference:

 

Try changing '$_post' to '$_POST'.

 

Try concatenation instead of using the variables directly - like this:

 

print 'The first name is:'. $name_first .'

';

 

And let us know what happens.

Link to comment
Share on other sites

Alright, problem solved!

 

It was the $_post vs $_POST. I tried your array before changing anything and the array caught the information but the $print function didn't. And then I changed the code to $_POST and everything displayed correctly.

 

I heard that the capitalization doesn't matter, is that maybe not true?

 

Thanks Monkeysaurus for your help!

 

Zac

Link to comment
Share on other sites

That's good to hear.

 

Variable names can be upper or lower case, although you should be consistent. I would suggest looking into camel case. Variable names are case sensitive, so $variable isn't the same as $VARIABLE or $Variable.

 

Pick a convention and stick to it.

 

For the superglobals ($_GET, $_POST, $_COOKIE, $_REQUEST, $_FILES etc) you should be using caps, or it won't work (as we found out :)). The superglobal arrays are variables like any other, and so are case sensitive.

 

I should have clocked that earlier, but it's almost midnight here. (That's my excuse and I'm sticking to it!) :P

 

All the best!

 

John

Edited by monkeysaurus
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...