note 71879 added to ref.mysql

From: Date: Wed, 20 Dec 2006 23:51:27 +0000
Subject: note 71879 added to ref.mysql
Groups: php.notes 
Request: Send a blank email to php-notes+get-120810@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: 64.71.164.2 Probable Submitter: 166.137.141.251 ---- Manual Page -- http://www.php.net/manual/en/ref.mysql.php Edit -- https://master.php.net/note/edit/71879 Del: integrated -- https://master.php.net/note/delete/71879/integrated Del: useless -- https://master.php.net/note/delete/71879/useless Del: bad code -- https://master.php.net/note/delete/71879/bad+code Del: spam -- https://master.php.net/note/delete/71879/spam Del: non-english -- https://master.php.net/note/delete/71879/non-english Del: in docs -- https://master.php.net/note/delete/71879/in+docs Del: other reasons-- https://master.php.net/note/delete/71879 Reject -- https://master.php.net/note/reject/71879 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120810) next »