<?php
require "../secure.php"; // Contains host, username and password
// IF ALL THE INPUT FIELDS ARE NOT BLANK ...
if (($_POST['title'] != "") &&
($_POST['last_name'] != "") &&
($_POST['first_name'] != "") &&
($_POST['date_of_birth'] != ""))
{
$link = mysql_connect($host, // Host name
$user, // User name
$password) // User password
or die("<h5>Could not connect: </h5>" . mysql_error());
if (mysql_select_db ($database))
{
$sql = "INSERT INTO customer
(title, last_name, first_name, date_of_birth)
VALUES
(\"$_POST[title]\", \"$_POST[last_name]\", \"$_POST[first_name]\", \"$_POST[date_of_birth]\")";
mysql_query($sql, $link);
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META name="description" content="Tutorial for Linux, Apache, MySQL, SQL and PHP - LAMP">
<META name="keywords" content="tutorial, linux, apache, mysql, php, code, sql, lamp, lesson, lessons, example, examples, beginner, beginners, beginners' beginner's">
<title>PHP and MySQL - INSERT INTO customer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table border="1" cellspacing="0" cellpadding="4">
<tr valign="top">
<td><?php include "nav.php"; ?></td>
<td>
<h1>PHP and MySQL - INSERT INTO customer</h1>
<?php
echo "<p>".$sql."</p>\n";
?>
<form name="form1" method="post" action="">
<table border="1" cellspacing="0" cellpadding="2">
<tr>
<td><div align="right">Title</div></td>
<td><input name="title" type="text" id="title"></td>
</tr>
<tr>
<td><div align="right">Last Name</div></td>
<td><input name="last_name" type="text" id="last_name"></td>
</tr>
<tr>
<td><div align="right">First Name</div></td>
<td><input name="first_name" type="text" id="first_name"></td>
</tr>
<tr>
<td><div align="right">Date of Birth yyyy-mm-dd</div></td>
<td><input name="date_of_birth" type="text" id="date_of_birth"></td>
</tr>
<tr>
<td colspan="2"><div align="right">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
</form>
<?php
require ("viewCode.php"); // Contains the viewData() code
viewData(); // Displays the SQL query results
dump_page(basename($_SERVER[SCRIPT_FILENAME])); // Display the code of this page
?>
</td>
</tr>
</table>
</body>
</html>
|