Simple PHP Help...

RWBRWB Icrontian
edited February 2005 in Internet & Media
OK, I have been trying to relearn PHP, I haven't ever spent much time with it so I have forgotten it since I last tinkered with it. I am using easyphp 1.7, from easyphp.org, I got it all up and working.

So I am starting anew, I am trying to work my way through my book of tutorials, and for some reason this one tutorial isn't working properly. Why??? Yes, I typed what is in the book exactly, I figure it is some kind of code variation between new and old version of PHP? I'm running 4.3.3 I believe of PHP.

Anyways the problem is that in neither case, POST nor GET I don't get the results back. I am supposed to get a "Welcome, User!" show up on the same page after submitting the characters name.

Using GET
[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<title>Example Form Processing</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body bgcolor="ffffff">
<form name="frmSample" action="exampleformproc_get.php" method="get">
<b>What is your character's name?</b><br>
<input type="text" name="strCharacter">
 <input type="submit" value="Submit">
</form>
<?php
if(isset($strCharcter))
{
echo("Welcome, " . $_REQUEST["strCharacter"] . "!");
}
?>
</body>
</html>
[/PHP]

Using POST
[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<title>Example Form Processing</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body bgcolor="ffffff">
<form name="frmSample" action="exampleformproc_post.php" method="post">
<b>What is your character's name?</b><br>
<input type="text" name="strCharacter">
 <input type="submit" value="Submit">
</form>
<?php
if(isset($_POST["strCharcter"]))
{
echo("Welcome, " . $_POST["strCharacter"] . "!");
}
?>
</body>
</html>
[/PHP]

BTW, when I use GET my address bar does in fact change. When using GET and place "Chris" in the form I recieve the following as my new address after submitting:

"http://localhost/php Game Programming/exampleformproc_get.php?strCharacter=Chris&quot;

When using POST nothing changes.

Comments

  • ShortyShorty Manchester, UK Icrontian
    edited February 2005
    You missed spelt it here:

    if(isset($_POST["strCharcter"]))

    should be..

    if(isset($_POST["strCharacter"]))

    :)
  • RWBRWB Icrontian
    edited February 2005
    DOH!! That did fix POST, but for some reason GET isn't working still. I have checked the spelling, and now that I can see why it didn't work before I can't see why it's not doing the same for GET.

    If there is a value for strCharacter it should show up with something, but I guess for some reason it's not finding a value for it?
  • ShortyShorty Manchester, UK Icrontian
    edited February 2005
    Change:

    if(isset($strCharcter))

    To:

    if(isset($_GET))

    :)
  • RWBRWB Icrontian
    edited February 2005
    Nope still not working, even tried:

    if(isset($_REQUEST))

    to no avail, amoungst other minor tweaks that didn't work either. :(
  • ShortyShorty Manchester, UK Icrontian
    edited February 2005
    [php]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml"&gt;
    <head>
    <title>Example Form Processing</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>

    <body bgcolor="ffffff">
    <form name="frmSample" action="exampleformproc_get.php" method="get">
    <b>What is your character's name?</b>
    <input type="text" name="test">
     <input type="submit" value="Submit">
    </form>

    <?php
    if(isset($_GET))
    {
    echo 'Welcome, '.$_GET.'!';
    }
    ?>
    </body>
    </html>
    [/php]
  • RWBRWB Icrontian
    edited February 2005
    Ahh, thank you. Here is what my problem was. Instead of:

    if(isset($_GET))
    {
    echo("Welcome, " . $_REQUEST . "!");
    }

    I had:

    if(isset($_GET))
    {
    echo("Welcome, " . $_REQUEST . "!");
    }

    I need a better eye for these very minor issues....
Sign In or Register to comment.