Skip to content

Instantly share code, notes, and snippets.

@mebrett
Created September 26, 2012 13:17
Show Gist options
  • Save mebrett/3787976 to your computer and use it in GitHub Desktop.
Save mebrett/3787976 to your computer and use it in GitHub Desktop.
code for adding new place to Maury database
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>HTML form for insert users</title>
</head>
<body>
<h2>Add Place to Maury Database</h2>
<form action="insert_place.php" method="post">
Place Name*: <input type="text" name="name" /><br />
Place Location: <input type="text" name="wider" /><br />
Notes: <input type="text" name="notes" /><br />
<input type="submit" value="Send" />
</form>
<p>Place location is the wider location in which the primary place is located. It is like the second location in an address. So for Place Name: London, the Place Location would be England, or for New York City, New York State.</p>
<p>*indicates a required field.</p>
</body>
</html>
<?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