By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,586 Members | 1,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,586 IT Pros & Developers. It's quick & easy.

problem with $_POST['foo']

P: 52
Hi I'm recenlty studying PHP myself
and I have got a problem in passing variables to one php script from another

i have following code as index.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $name=HREEDN
  3. ?>
  4. <html>
  5. <head>
  6. <title><?php print ("$name")?> in PHP</title>
  7. <h1><font color=BLUE><center>WELCOME TO HREEDN</center></font></h1>
  8. </head>
  9. <body bgcolor=gold>
  10. <center><table width=80%>
  11. <tr>
  12. <td><a href= index.php><center>Home</center></a></td>
  13. <td><a href= search.php><center>Search Friends</center></a></td>
  14. <td><a href= images.php><center>View Images</center></a></td>
  15. <td><a href= contact.php><center>Contact Me</center></a></td>
  16. </tr>
  17. </table>
  18. </center>
  19. <table width=100%>
  20. <tr>
  21. <td width=50%>
  22. <font size=2 face=arial>
  23. <br>
  24. <P>This site is currently being developed by a novice php programmer
  25. and please help this php programmer by filling the form and commenting.
  26. </P>
  27. <P>
  28. You can send the feedback to [EMAIL REMOVED]<br>
  29. or just use the link above
  30. </P>
  31. </font>
  32. </td>
  33. <td width=50%>
  34. <br/><br/><br/>
  35.  
  36. <form action="confirm.php" method="POST">
  37. <P>
  38. <b>
  39. First Name: <input type="text" NAME="fname"><br/>
  40. Last Name: <input type="text" NAME="lname"><br/>
  41. Age: <input type="text" NAME="age"><br/>
  42. Semester: <input type="text" NAME="sem"><br/>
  43. </b>
  44. </P>
  45. <br/>
  46. <input type=submit value="Done">
  47. <input type=reset value="Clear">
  48. </form>
  49. </td>
  50. </tr>
  51. </table>
  52. </body>
  53. </html>
  54.  
and i have a confirm.php file as
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Confirm the data</title>
  4. <h1><font color=BLUE><center>WELCOME TO HREEDN</center></font></h1>
  5. </head>
  6. <body bgcolor=gold>
  7. <center><table width=80%>
  8. <tr>
  9. <td><a href= index.php><center>Home</center></a></td>
  10. <td><a href= search.php><center>Search Friends</center></a></td>
  11. <td><a href= images.php><center>View Images</center></a></td>
  12. <td><a href= contact.php><center>Contact Me</center></a></td>
  13. </tr>
  14. </table>
  15. </center>
  16. <?php
  17. printf ("First Name:", $_POST['fname']);
  18. print ("\n<br/>\n");
  19. print ("Last Name: $_POST['lname']");
  20. print ("\n<br/>\n");
  21. print ("Age: $_POST['age']");
  22. print ("\n<br/>\n");
  23. print ("Sem: $_POST['sem']");
  24. ?>
  25. </body>
  26. </html>
  27.  
but when i try filling the form and submit
it shows a blank page
i don't know the reason
but if i use $variable instead of $_POST['variable']
and use GET method it shows a html page without the values in variable

how can i solve this problem
thanks
Jul 30 '07 #1
Share this Question
Share on Google+
9 Replies


nathj
Expert 100+
P: 938
Hi shreedhan,

Wlecome to TSDN!

Try changing the code a little. I would replace print(....) lines with:
Expand|Select|Wrap|Line Numbers
  1. echo 'First Name:' . $_POST['fname'] . '<br />';
  2. echo 'Last Name:' . $_POST['lname'] . '<br />';
  3. echo 'Age:' . $_POST['age'] . '<br />';
  4. echo 'Semester:' . $_POST['sem'] . '<br />';
  5.  
Give that a try and see how you get on

Also the input type=submit shoud be input type="submit" I think. So load the quotes around it. That's certainly the way I do not.

If none of this works turn on the error handling and see what comes up.

Cheers
nathj
Jul 30 '07 #2

kovik
Expert 100+
P: 1,044
Try changing the code a little. I would replace print(....) lines with:
Expand|Select|Wrap|Line Numbers
  1. echo 'First Name:' . $_POST['fname'] . '<br />';
  2. echo 'Last Name:' . $_POST['lname'] . '<br />';
  3. echo 'Age:' . $_POST['age'] . '<br />';
  4. echo 'Semester:' . $_POST['sem'] . '<br />';
  5.  
print() and echo() are the EXACT same thing.

Also the input type=submit shoud be input type="submit" I think. So load the quotes around it.
Quotation marks only make a difference when the name you are using has a space in it. It is also the proper mark up, but it wouldn't be the cause of error in this case.

but when i try filling the form and submit
it shows a blank page
i don't know the reason
but if i use $variable instead of $_POST['variable']
and use GET method it shows a html page without the values in variable
It shows absolutely nothing? Not even the HTML that you already have? Be more descriptive of what you actually see.

And so you know, printf() is not the same as print() and has completely different rules for the way that it works. I'll assume you used it by accident in the first call. Fix it.
Jul 30 '07 #3

nathj
Expert 100+
P: 938
print() and echo() are the EXACT same thing.
I know, I was just suggesting an alternative to get it re-written as I think there may be issues with the way the print function is being used.

Am I correct in thinking that
Expand|Select|Wrap|Line Numbers
  1. print ("Last Name:  $_POST['lname']");
  2.  
should really be:
Expand|Select|Wrap|Line Numbers
  1. print('Last Name: ' . $_POST['lname']);
  2.  
I guess I was trying to ensure that the original line was re-written in accordance with something I knew for sure worked.

Cheers
nathj

ps kudos on the web site!
Jul 30 '07 #4

kovik
Expert 100+
P: 1,044
Am I correct in thinking that
Expand|Select|Wrap|Line Numbers
  1. print ("Last Name:  $_POST['lname']");
  2.  
should really be:
Expand|Select|Wrap|Line Numbers
  1. print('Last Name: ' . $_POST['lname']);
  2.  
I guess I was trying to ensure that the original line was re-written in accordance with something I knew for sure worked.
You are correct in stating that arrays should not be entered into the string in that manner, but I'm not sure if that would cause it to no longer work. If he removes the "f" in printf(), and suddenly that line begins to work, then the arrays would be the culprit.
Jul 30 '07 #5

P: 52
I know, I was just suggesting an alternative to get it re-written as I think there may be issues with the way the print function is being used.

Am I correct in thinking that
Expand|Select|Wrap|Line Numbers
  1. print ("Last Name:  $_POST['lname']");
  2.  
should really be:
Expand|Select|Wrap|Line Numbers
  1. print('Last Name: ' . $_POST['lname']);
  2.  
Thanks both of you Volectricity and Nathj
the code is now running as I replaced
print ("Last Name: $_POST['lname']");
with
print ("Last Name:". $_POST['lname']);

and Volectricity I was using printf() function randomly to check if it works

and further when I meant blank page, it showed nothing, not even HTML code i had written.

Anyway, my problem is solved now
Thank you guys again
Jul 30 '07 #6

nathj
Expert 100+
P: 938
Hi,

Glad you got it working.

All the best with the project

Cheers
nathj
Jul 30 '07 #7

kovik
Expert 100+
P: 1,044
Yeah, on second thought, I think the only way to put arrays INTO the string is like so:

[php]$str = "foo: {$_POST['foo']}";[/php]
Jul 30 '07 #8

P: 52
Hi,

Glad you got it working.

All the best with the project

Cheers
nathj
Thanks for your wishes.

I have one more question to ask.
I am getting values of all the variables from index1.php to confirm.php
now can I pass these values from confirm.php to some other.php file
so that I can use them to pass into database?

Thanks
Jul 31 '07 #9

ak1dnar
Expert 100+
P: 1,584
Thanks for your wishes.

I have one more question to ask.
I am getting values of all the variables from index1.php to confirm.php
now can I pass these values from confirm.php to some other.php file
so that I can use them to pass into database?

Thanks
You may better to use sessions.
Jul 31 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.