user1886122
user1886122

Reputation: 1

Why isn't this simple sign up page working?

I'm not sure why this isn't working, It is giving me no errors, but it won't display the results. I just want to display the results of the 3 text fields. The next step I want to go about doing is entering the data into a database, then displaying it, but I guess that will come next. Thank you.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php
$Fname = $_POST["Fname"];
$Lname = $_POST["Lname"];
$Pword = $_POST["Pword"];

if (!isset($_POST['submit'])) { // if page is not

?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<form method = "post" action = "<?php echo $PHP_SELF;?>">

First name<input name="Fname" type="text" maxlength="12"
/>
<br />
<br />

Last name<input name="Lname" type="text" maxlength="12"
/>
<br />
<br />

<!--Address <input name="register_address" type="text" maxlength="12"
/>
<br />
 <br />-->
<!--<select name="state" value="State"></select>-->


Password<input name="Pword" type="text" maxlength="12"
/>
<br />
<br />

<!--Re-type Password<input name="register_password_confirm" type="text" maxlength="12"
/>
<br />
<br />-->

<input name="submit" type="button" value="Submit" />



</form>

<?
} else {
echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "Your Password is, " .$Pword.".<br />";
}
?>




</body>
</html>

Upvotes: 0

Views: 82

Answers (4)

jnthnjns
jnthnjns

Reputation: 8925

Your submit button needs to be changed to type="submit", also you might want to move your variable declarations within the else statement to avoid PHP warnings:

<input name="submit" type="submit" value="Submit" />

and:

<?php
} else {
    $Fname = $_POST["Fname"];
    $Lname = $_POST["Lname"];
    $Pword = $_POST["Pword"];
    echo "Hello, ".$Fname." ".$Lname.".<br />";
    echo "Your Password is, " .$Pword.".<br />";
}
?>

Lastly, I would reduce the amount of html you put it the if statement to the bare minimum, this could cause conflicts if you change how the condition is handled in the future:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Untitled Document</title>
    </head>
    <body>

    <?php
    if (!isset($_POST['submit'])) { // if page is not
        ?>
        <form method = "post" action = "<?php echo $_SERVER['PHP_SELF'];?>">
            First name<input name="Fname" type="text" maxlength="12" /><br /><br />
            Last name<input name="Lname" type="text" maxlength="12" /><br /><br />
            <!--Address <input name="register_address" type="text" maxlength="12" /> <br /> <br />-->
            <!--<select name="state" value="State"></select>-->
            Password<input name="Pword" type="text" maxlength="12" /><br /><br />
            <!--Re-type Password<input name="register_password_confirm" type="text" maxlength="12" /><br /><br />-->
            <input name="submit" type="submit" value="Submit" />
        </form>
        <?php
    } else {
        $Fname = $_POST["Fname"];
        $Lname = $_POST["Lname"];
        $Pword = $_POST["Pword"];
        echo "Hello, ".$Fname." ".$Lname.".<br />";
        echo "Your Password is, " .$Pword.".<br />";
    }
    ?>
    </body>
</html>

Upvotes: 1

Michael
Michael

Reputation: 12806

Three issues I see

1 - Your button is not a submit button

Change:

<input name="submit" type="button" value="Submit" />

to

<input name="submit" type="submit" value="Submit" />

2 - Register globals may be turned off

Change:

<?php echo $PHP_SELF;?>

to

<?php echo $_SERVER['PHP_SELF'];?>

3 - Short open tags may be turned off

Change:

<?
} else {
echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "Your Password is, " .$Pword.".<br />";
}
?>

to

<?php
} else {
echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "Your Password is, " .$Pword.".<br />";
}
?>

Upvotes: 3

useyourillusiontoo
useyourillusiontoo

Reputation: 1367

try echoing the result like this:

echo "Hello, $Fname $Lname.<br />
      Your Password is, $Pword.<br />";

I forgot to add that you don't need the dots after variables when echoing using double quotations.

Upvotes: 0

andrewvnice
andrewvnice

Reputation: 463

Try adding a

<input type="hidden" name="submitted" value="1" />

and checking for

$_POST['submitted'] == 1

Upvotes: 0

Related Questions