473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

problem with $_POST['foo']

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
9 1950
nathj
938 Expert 512MB
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
1,044 Expert 1GB
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
938 Expert 512MB
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
1,044 Expert 1GB
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
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
938 Expert 512MB
Hi,

Glad you got it working.

All the best with the project

Cheers
nathj
Jul 30 '07 #7
kovik
1,044 Expert 1GB
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
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
1,584 Expert 1GB
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

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

Similar topics

4
by: Randell D. | last post by:
Folks, I test if my PHP should process form data by checking if $_POST is an array - However I always find its condition proves true - Why or alternatvily, what other method can one use to check...
12
by: Mosher | last post by:
Hi all, I have an issue with php and/or mysql. I have a php form that writes "items" to a mysql database, including a description of the item. On the mysql server, "magic_quotes_gpc" is ON. I...
12
by: AJ Z | last post by:
I am using in_array() to search for a value ("other"), in order to validate a form. If I pass $_POST as the array to search PHP says that it is an invalid datatype. It is an array and if I copy...
4
by: Chris | last post by:
I'm trying to learn PHP, and I'm having a strange problem with my local install on SuSE 9.0. I have a script here: http://www.little-people-austin.com/~chris/estpop.php Here, it works fine....
5
by: Collie | last post by:
PHP version 5.1.1 Apache 2.0.55. code; index.html <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html;
2
by: Jacob Lyles | last post by:
Hello, I'm using the following function to display a list of files in a directory in a HTML form that allows the user to delete files. Look at the echo line. The links work fine, taking a user...
9
by: weird0 | last post by:
How does C++ and C# solve the Diamond problem? With the help of interfaces that is. Can anyone elaborate ....... Regards
7
by: lawpoop | last post by:
Hello all - Is there a way to get a nested array in a $_POST variable? I have a form where there are several questions, each one corresponding to a database row. On submission of the form, I...
32
by: Bill H | last post by:
I wouldn't consider myself a newbie to PHP since I have never written one line of code in it (am a perl guy myself), but part of a team I am working with is writing some php interfaces into a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.