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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.