Skip to content

Instantly share code, notes, and snippets.

@ezos86
Created August 2, 2013 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezos86/6138174 to your computer and use it in GitHub Desktop.
Save ezos86/6138174 to your computer and use it in GitHub Desktop.
This is a basic Database Insert
<!DOCTYPE>
<html>
<head>
<title></title>
</head>
<body>
<form action="db-insert.php" method="post">
<label for="firstName">First Name:</label>
<input id="firstName" name="firstName" value="" />
<br>
<label for="lastName">Last Name:</label>
<input id="lastName" name="lastName" value="" />
<br>
<label for="age">Age:</label>
<input id="age" name="age" value="" />
<input type="submit" />
</form>
</body>
</html>
<?php
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$age = $_POST['age'];
echo $firstName . ' ' . $lastName . ' '. $age;
$dbn = mysqli_connect('localhost', 'root', '', 'peach_db') or die(mysqli_error('error'));
$query = "INSERT INTO Persons (PID,FirstName, LastName, Age) VALUES (Null,'".$firstName."','".$lastName."',".$age.")";
echo $query;
mysqli_query($dbn,$query) or die(mysql_error($dbn));
mysqli_close($dbn);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment