Jump to content

Newbie help please


extremeshannon

Recommended Posts

This is a simple php program and it doesn't work the way it is suppose to. The page see's $username as empty. I have not been able to fix it. I am reading a book and following all the code but anything passing variables to another page or with in the page is not working for me. any help would be great.

 

<html>
<head>
<title>Hi User</title>
</head>
<body>
<h1>Hi User</h1>
<?
if (empty($userName)){

print <<<HERE
<form>
please enter you name:
<input type = “text”
name = “userName”>
<br>
<input type = "submit">
</form>
HERE;
}else{
print "<h3>Hi There, $userName !</h3>";
}//end

?>
</body>
</html>

Link to comment
Share on other sites

Thanks for the help.

I am trying to follow the book as close as possible. and the book has shortcuts like <? I did change this to <?php and plan on using that in my code. I did change the quotes did not see that this time must have copied that to make sure I was typing correct. The page is URL encoding (I believe this is what it is doing) hiUser2.php?"userName"=Shannon but the page is not changing. I have tried this on my website I have running and on my localhost and get the same results.

 

Thanks again

Link to comment
Share on other sites

There is no $_POST form for that script, unless you want to retrieve from a $_GET

 

some changes

 

<html>
<head>
<title>Hi User</title>
</head>
<body>
<?php
$userName = $_POST['userName'];
if (empty($userName)){

print <<<HERE
<h1>Hi User</h1>
<form action="" method="post">
please enter you name:
<input type = "text"
name = "userName">
<br>
<input type = "submit">
</form>
HERE;
}else{
print "<h1>Hi There, $userName !</h1>";
}//end

?>
</body>
</html>

Link to comment
Share on other sites

One of my favorites is PHP for Absolute Beginners.

 

I know you said you weren't doing the code anymore, but I have to add something:

 

<input type = “text”
name = “userName”>

 

I'm going to guess, that since you're not using $_GET or $_POST (which you should be to pass the data), another issue could be the use of those special quotes are messing things up a bit too. Just use regular double quotes. I could be wrong about that though.

Link to comment
Share on other sites

To be honest many of the books , even though they have newer versions, still have old or incorrect practices in them.

Most of the time you are just copying chunks of code and they briefly inform you on some of the why, and alternate methods.

 

In general it will be what that author felt it should be.

 

There are a few places to get you started online.

http://www.tizag.com/phpT/index.php

http://www.w3schools.com/php/

http://devzone.zend.com/6/php-101-php-for-the-absolute-beginner/

http://www.web3mantra.com/2011/06/21/35-best-php-video-tutorials/

 

And the best place yet, the php manual, usually with some examples and explanations.

http://php.net/manual/en/tutorial.php

 

And if ever get stuck with a code, can always drop into phpfreaks for assistance.

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.