Noob post _SELF problems
Posted: Wed Sep 09, 2009 3:47 pm
Hi all,
Just starting out with php and wanting to create a dead-simple form that post to the same page. Gone through lots of tutes and examples and still can't get a proper working piece of code!
This is what I have, written in phpDesigner and running on WAMP
I get 'undefined variable' errors for Fname and Lname after submitting. Replacing the second half with HTML code instead of php, from line 19 onwards...
I've been at this for a few days now.
I had the variables working at one point, but the Submit variable didn't. What an I doing wrong?!
Just starting out with php and wanting to create a dead-simple form that post to the same page. Gone through lots of tutes and examples and still can't get a proper working piece of code!
This is what I have, written in phpDesigner and running on WAMP
Code: Select all
<?php
if (!isset($_POST['Fname'])){
$Fname = '';}
if (!isset($_POST['Lname'])){
$Lname = '';}
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br />
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />
<input type="submit" value="submit" name="submit">
</form>
</body>
<?php
} else {
echo '<html>';
echo '<head>';
echo '<title>Personal INFO</title>';
echo '</head>';
echo '<body>';
echo "Hello, ".$Fname." ".$Lname.".<br />";
echo '</body>';
};
?>Code: Select all
<?php
} else {
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
Hello, <?php echo $Fname?> <?php echo $Lname?>. It's lovely here.<br>
<?php
};
?>