Jump to content

Problem getting PHP to process variables (I think)


Recommended Posts

 

I hate to ask such a n00b question, but...

I am trying to learn PHP. So far, I have only learned basic syntax, operators, print and echo, array syntax, function syntax, and do/while and for loops. The main reason I am having great difficulty learning is because I have a hard time learning the material if I can't implement it or practice with it, i.e. use the new knowledge in a working PHP script. However, the first time I installed PHP, I was able to get some scripts to work properly, like a basic <?php phpinfo(); ?> script, and another one that checks what browser you are using, but any time I try to run a script with a variable, it fails. Before I get into the details of that; one time I was so frustrated I just started turning random PHP extensions on that normally come preconfigured as off, and I got it to work. But then, 2 new PHP versions came out and I figured I better upgrade for the security fixes (I had forgotten about the problems I had had in the beginning) and so now I'm back to square one with 5.21

 

Consider the following 2 documents:

 

whatsName.html

 

<html>

<head>

<title>What's your name?</title>

</head>

<body>

<h1>What's your name?</h1>

<h3>Writing a form for user input</h3>

<form method = "get"

      action = "hiUser.php">

Please type your name:

<input type = "text"

      name = "userName"

      value = "">

 

 

<input type = "submit">

 

</form>

</body>

</html>

 

and

 

hiUser.php

 

<html>

<head>

<title>Hi User</title>

</head>

<body>

<h1>Hi User</h1>

<h3>PHP program that receives a value from "whatsName"</h3>

 

<?php

 

  print "<h3>Hi there, $userName !</h3>";

 

?>

 

</body>

</html>

 

 

Now, both are in the same directory, contained in a Project folder in my www folder, and both are in the same directory as the phpinfo() script that does work along with the browser detector script that also does work. When I type an input and hit submit, it loads hiUser.php, but there is no data where the variable should be. On other scripts, it will either give me a garbled piece of the script near where the variable is dealt with, or it will again display nothing at all. This only seems to be a problem with scripts containing variables.

 

Any suggestions?

 

Link to comment
Share on other sites

Hmm.. Try not to manully install PHP yourself if you're not very sure what extension needed to be activated. Install WAMP for script testing purposes.

 

Try not to use GET for the method, use POST instead.

 

In your hiUser.php

Replace $userName with $_POST['userName']

 

Hope that helps.

Link to comment
Share on other sites

Hmm.. Try not to manully install PHP yourself if you're not very sure what extension needed to be activated. Install WAMP for script testing purposes.

 

Try not to use GET for the method, use POST instead.

 

In your hiUser.php

Replace $userName with $_POST['userName']

 

Hope that helps.

 

Well, for one thing, I did use WAMP. I haven't messed with it at all... for some reason it doesn't like to work with the standard preconfig settings. Replacing $userName with what you suggested caused an error... so not sure. Also, both documents I posted are taken directly from a PHP/mySQL book I bought, and they are both unedited files from the book's CD.

Link to comment
Share on other sites

UPDATE:

 

Ok I've narrowed down the problem a little bit. It seems the only scripts that are failing are ones that start with an html document which sends data to a php document that displays the results. All php documents in my www folder work properly except for these... any ideas?

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.