note 73152 added to tutorial.forms

From: Date: Sun, 11 Feb 2007 01:47:25 +0000
Subject: note 73152 added to tutorial.forms
Groups: php.notes 
Request: Send a blank email to php-notes+get-123231@lists.php.net to get a copy of this message
Here is a complete real world PHP MySQL example which displays a form, connects to a database, inserts form fields, and redirects. Although this code was automatically generated from a PHP MySQL framework, http://www.wizzyweb.com it is pretty much the same as what would be written from scratch. I found it useful as it shows how PHP MySQL functions are actually used in a complete application: <?php // DESCRIPTION // Displays Form, Inserts Form data into Database Table and Redirects $EmployeeFirstName = $_REQUEST["EmployeeFirstName"]; $EmployeeLastName = $_REQUEST["EmployeeLastName"]; if ($_SERVER['REQUEST_METHOD'] == 'GET'){ echo '<TABLE WIDTH=450 BORDER=0 CELLSPACING=0 CELLPADDING=3> <TR BGCOLOR=#OOOO84> <TD COLSPAN=2><STRONG><FONT COLOR=#FFFFFF> Form</FONT></TD> </TR> <FORM METHOD=POST> <TR VALIGN=TOP BGCOLOR=#BFBFBF> <TD ALIGN=RIGHT> EmployeeID</TD> <TD><INPUT TYPE=TEXT NAME=EmployeeID SIZE=40 MAXLENGTH=256 VALUE=></TD> </TR> <TR VALIGN=TOP BGCOLOR=#BFBFBF> <TD ALIGN=RIGHT> EmployeeFirstName</TD> <TD><INPUT TYPE=TEXT NAME=EmployeeFirstName SIZE=40 MAXLENGTH=256 VALUE=></TD> </TR> <TR VALIGN=TOP BGCOLOR=#BFBFBF> <TD ALIGN=RIGHT> EmployeeLastName</TD> <TD><INPUT TYPE=TEXT NAME=EmployeeLastName SIZE=40 MAXLENGTH=256 VALUE=></TD> </TR> <TR ALIGN=CENTER BGCOLOR=#BFBFBF> <TD COLSPAN=2><INPUT TYPE=SUBMIT VALUE=Submit> <INPUT TYPE=RESET VALUE=Reset></TD> </TR> </FORM> </TABLE>'; } else { $link = mysql_connect('localhost', 'wizzyweb', 'password') or die('Could not connect: ' . mysql_error()); mysql_select_db('wizzyweb') or die('Could not select database'); $query = "INSERT INTO Employees (EmployeeFirstName, EmployeeLastName) VALUES ('$EmployeeFirstName', '$EmployeeLastName');"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Closing connection mysql_close($link); header("Location: http://www.wizzyweb.com"); } ?> ---- Server IP: 216.194.113.175 Probable Submitter: 166.137.229.220 ---- Manual Page -- http://www.php.net/manual/en/tutorial.forms.php Edit -- https://master.php.net/note/edit/73152 Del: integrated -- https://master.php.net/note/delete/73152/integrated Del: useless -- https://master.php.net/note/delete/73152/useless Del: bad code -- https://master.php.net/note/delete/73152/bad+code Del: spam -- https://master.php.net/note/delete/73152/spam Del: non-english -- https://master.php.net/note/delete/73152/non-english Del: in docs -- https://master.php.net/note/delete/73152/in+docs Del: other reasons-- https://master.php.net/note/delete/73152 Reject -- https://master.php.net/note/reject/73152 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123231) next »