Jump to content

variable help please


-entropyman

Recommended Posts

Hello all,

 

as you can tell i am still very new at php. i am learning from a book i bought. now i have run across a problem and would like your help.

 

i am just doing the simple hi user exercise but i cannot figure out what is going wrong. i enter a name in the text field and hit submit but on the next page it just says "Hi there, !"

 

http://entropy.vndv.com/learning/chapter_2/whatsName.html

 

as you can see you still enter a name in the text field and hit submit but on the next page it just says "Hi there, !"

 

any ideas?

 

thank you  :)

Link to comment
https://forums.phpfreaks.com/topic/112301-variable-help-please/
Share on other sites

Without seeing the code you are using, its a bit difficult to help you there.

 

Double check that you've not made a mistake with your variable, and note that it is case sensitive. You could have something like:

 

$userName = $_POST['userName'];

 

If you're still stuck, we need to see your code. Dont forget to place


tags around it.

 

p.s. Welcome to the forum

Link to comment
https://forums.phpfreaks.com/topic/112301-variable-help-please/#findComment-576574
Share on other sites

well thank you mate, but i now get this error

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /www/vndv.com/e/n/t/entropy/htdocs/learning/chapter_2/hiUser.php on line 11

 

before i was just using $userName - the code i am testing is straight outta my learning book.

 

here is the code

 

<html>
<head>
<title>Hi User</title>
</head>
<body>
<h1>Hi User</h1>
<h3>PHP program that receives a value from "whatsName"</h3>

<script language = "php"> 

print "<h3>Hi there, $_POST['userName']!</h3>";

</script>

</body>
</html>

any ideas?  thanks in advance  ;)

 

and thank you for the welcome  :D

Link to comment
https://forums.phpfreaks.com/topic/112301-variable-help-please/#findComment-576581
Share on other sites

The book you're using assumed that global variables are turned on which hasn't been the default for over 5 years.

 

If you had posted the original script, then we could have given you the correct line.

 

You need to do

<?[php
print "<h3>Hi there, {$_POST['userName']}!</h3>";
?>

 

Also the more accepted way of entering/exiting PHP code blocks is with "<?php ?>", not "<script language = "php"> </script>".

 

Please buy a more up to date book. If you learn from the one you have, you will probably learn old & insecure programming methods.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/112301-variable-help-please/#findComment-576644
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.