Created
September 26, 2012 13:15
-
-
Save mebrett/3787968 to your computer and use it in GitHub Desktop.
code for adding new person to Maury database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html> | |
<head> | |
<title>Form to Insert Persons, Maury1a</title> | |
</head> | |
<body> | |
<h2>Create New Person Record</h2> | |
<p>This form creates a new person record for the database Maury1a. Please include as much information as possible.</p> | |
<form action="insert4.php" method="post"> | |
First Name: <input type="text" name="firstname" /><br /> | |
Middle Name: <input type="text" name="midname" /><br /> | |
*Last Name: <input type="text" name="lastname" /><br /> | |
Date of Birth: <input type="text" name="dob" /> | |
Date of Death: <input type="text" name="dod" /><br /> | |
Notes: <input type="text" name="notes" /><br /> | |
<input type="submit" value="Send" /> | |
</form> | |
<p>Dates must be entered as mm/dd/yyyy. Fields marked with * are required.</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//connect to database | |
$con = mysql_connect('server', 'user', 'password'); | |
//check connection | |
if (!$con) { | |
die('Could not connect');} | |
/*else{echo 'Connection success<br />';}*/ | |
mysql_select_db('maury1'); | |
//store values | |
$placeN=mysql_real_escape_string($_POST['name']); | |
$placeW=mysql_real_escape_string($_POST['wider']); | |
$note=mysql_real_escape_string($_POST['note']); | |
//Check to make sure a last name is entered | |
if ($placeN == ""){ | |
die('Error! Last name is a required field.<br /><a href="form_place.php">Go back</a>');} | |
//formulate query | |
$new_name = "INSERT INTO place (place_no, place_name, place_wider, place_notes) VALUES ('NULL', '".$placeN."', '".$placeW."', '".$note."')"; | |
//submit query | |
mysql_query($new_name) or die('Error '. mysql_error()); | |
//get new prime key | |
$newPid = mysql_insert_id(); | |
echo "Success: $placeN added with unique id $newPid"; | |
echo "<br /> <a href='form2.html'>Back</a>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment