Skip to content

Instantly share code, notes, and snippets.

@jakirseu
Created February 7, 2016 18:11
Show Gist options
  • Save jakirseu/94bb6babdce8b14d2fa4 to your computer and use it in GitHub Desktop.
Save jakirseu/94bb6babdce8b14d2fa4 to your computer and use it in GitHub Desktop.
<?php
$servername = "localhost"; // set your server address.
$username = "username"; // set your database username
$password = "password"; // give your db user password
$dbname = "db_name"; // change this to your data base name
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// get posted data
$name= $_POST['name'];
$email = $_POST['email'];
// save into database
$sql = "INSERT INTO table_name(name, email)
VALUES ('$name', '$email')";
// check if success
if (mysqli_query($conn, $sql)) {
echo 'data saved';
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment