Created
February 7, 2016 18:11
-
-
Save jakirseu/94bb6babdce8b14d2fa4 to your computer and use it in GitHub Desktop.
This file contains 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 | |
$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