473,395 Members | 1,905 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,395 software developers and data experts.

problem with variables working cooperatively... extreme newbie

10
below i have code from a simple php form program. you are supposed to enter your name in a text box and push the submit button. it then is supposed to bring you to a page that says "hello --your name here-- "
but instead it says "Hello $userName!; ?>" i tried rewriting it, ive tried fixing it different ways, and i thought maybe it had something to do with "register_globals" but i have a severe lack of understanding of it. however i do have it turned on (as i remember). anyways, here is the code of the original page first and after i will have the code of the second page. thanks

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title> psuedo login </title>
  4. </head>
  5.  
  6. <body>
  7. <h1> What is your name?</h1>
  8. <h3> form for user input</h3>
  9. <form method = "post"
  10.     action = "hiUser.php">
  11. Please type name here:
  12. <input type = "text"
  13.     name = "userName"
  14.     value = "">
  15.  
  16. <br>
  17. <input type = "submit">
  18.  
  19. </form>
  20. </body>
  21. </html>
  22.  
  23.  
now here is the second page
Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <title> then you must be...</title>
  5. </head>
  6.  
  7. <body>
  8.  
  9.  
  10. <h1>Hi User</h1>
  11. <h3> php program that recieves a value from "index.html"</h3>
  12.  
  13. <?
  14. print <h3> Hello $userName!</h3>;
  15.  
  16. ?>
  17.  
  18. </body>
  19. </html>
Jul 12 '08 #1
9 1273
Markus
6,050 Expert 4TB
Try putting your print statement in quotes.

Expand|Select|Wrap|Line Numbers
  1. print "hello";
  2.  
Jul 12 '08 #2
to use the 'username' variable on the new page you need to access it by using $_POST['username']...
Jul 12 '08 #3
montana
10
wow, thats really funny. ive been reading out of this php book that i got as a gift and it didnt even mention the post command. what a piece of garbage. thanks guys
Jul 12 '08 #4
montana
10
alright well i tested it out and it didnt work... instead of posting "hello --your name here--" it doesnt show anything at all. this is SO confusing. can someone please PLEASE give me an idea where to go from here?
Jul 12 '08 #5
Markus
6,050 Expert 4TB
alright well i tested it out and it didnt work... instead of posting "hello --your name here--" it doesnt show anything at all. this is SO confusing. can someone please PLEASE give me an idea where to go from here?
You're using shorttags (<? /*code*/ ?>) try using full tags (<?php /*code*/?>)

That book seems abit out-dated.

The code would work, had register_globals been enabled.
Jul 12 '08 #6
montana
10
well im curious now, what version of php is the most current stable version?
Jul 13 '08 #7
montana
10
the full tags didnt do the trick. im running out of ideas. i think maybe there might be something wrong with my .ini file? or something i did wrong in the setup maybe? i even did a cross browser check and its all the same.
Jul 13 '08 #8
coolsti
310 100+
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title> then you must be...</title>
  4. </head>
  5.  
  6. <body>
  7.  
  8.  
  9. <h1>Hi User</h1>
  10. <h3> php program that recieves a value from "index.html"</h3>
  11.  
  12. <?php
  13. $userName = trim($_POST['userName']);
  14. echo "<h3> Hello " . $userName . "!</h3>";
  15.  
  16. ?>
  17.  
  18. </body>
  19. </html>
  20.  
  21.  
Try the above. The changes I make are as follows:

1) use of <?php instead of <? as PHP tag.
2) echo instead of print. Maybe print works fine, I just never used it :)
3) I broke up the argument to the echo statement to three pieces using the string concatenation symbol which is a period. I did this because you have a ! just after the PHP variable name. This is probably no problem, but I do this just to make sure the line is handled correctly by PHP. There are many ways of writing this line, but what I did above should work.
4) You need to retrieve the value of userName from the $_POST array. Note that the $_POST array may be case sensitive. I use Linux, which definitely is case sensitive, so in this case "userName" would be present but "username" would not be! I am not sure about PHP on Windows, whether that is case sensitive, but it is best to keep case sensitivity in case you ever need to port your scripts.

If the above does not work, then you need to examine your $_POST array and see if it is present and correct. To do this, try putting this statement in the script above, after the <body> tag:

echo "<pre>";
print_r($_POST);
echo "</pre>";

That should print a listing of your $_POST array. If it is empty or you do not see the entry for 'userName', then you need to inspect your php configuration to see why. Also make sure that the page that calls this script (the one the user submits) is properly set up such that the submit button and the userName input field are contained within the same form tags (if you put two sets of form tags on your page or made some mistake here, you may not get the input values to your $_POST correctly.
Jul 13 '08 #9
try to use the global variable $_POST and don't forget that the print function has one parameter
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title> then you must be...
  4. </head>
  5. <body>
  6.  
  7. <h1>Hi User
  8. <h3> php program that recieves a value from "index.html"
  9.  
  10. <?php
  11.  
  12. print "<h3> Hello ".$_POST['userName']."!"; 
  13. ?>
  14.  
  15. </body>
  16. </html>
Jul 15 '08 #10

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

Similar topics

2
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their...
2
by: deko | last post by:
I use variables in some links on my page. I need to send these variables so I can change the color of the links in the navbar when the user is on that page. If you click around on the site you...
2
by: C16 | last post by:
Hi All Another newbie question. I have a small website working via php and all is fine, but I wanted to add some new features and was wondering if php allows for variables to be seen by multiple...
20
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
14
by: Cylix | last post by:
I have a array to store some student information, eg var s = new Array('2006001', 'Apple Joker', '5B'); normally, We get the data using s, s,s ... How can I define them more readable like s, s,...
0
by: WORKING IN FAITH | last post by:
three years I LOVE You Monica More options 1 message - Collapse all WORKING IN FAITH View profile More options Nov 13, 11:29 am three years I LOVE You Monica
6
by: SuperFool | last post by:
This has got to be one of those questions only a serious newbie would come up with.... Basicly: I select all the city names in the table and turn them into a pull down menu (code below) print...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
6
by: BoscoPippa | last post by:
I'm an extreme newbie at C++ and am working on my final project for my beginner course. I have an issue, though, and I'm hoping I can get a nudge in the right direction. The program functions via...
22
by: V S Rawat | last post by:
(bringing the discussion here for php.general) I am on xpsp3, wampserver 2.0, having apache 2.2.8, php 5.2.6, MySQL 5.0.51b. http://localhost/ is E:\wamp\www\ I have put the first php script...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.