faqts : Computers : Programming

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

16 of 24 people (67%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Is it right to use if (submit) {...} If i'm embedding the php above a form?

Oct 6th, 2006 17:46
Chad Currie, TeraZen, Vijay Thakorlal, ny dr, http://www.blogvoid.com/


Yes it is. Here is an example of a page that contains a form and the 
php
code to handle the user submitted data in the same file:
--------------------------------------------------------------------
<?php
if($_POST["submit"]){
$Fname = $_POST["Fname"];
$Lname = $_POST["Lname"];
echo "Hello, ".$Fname." ".$Lname.".<br />";
}
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="<?php echo $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>
</html>
The name of your button MUST be "submit"!
Be careful with the newer versions of PHP! You should need to retrieve
the submit value with $_GET or $_POST!