Skip to content

Instantly share code, notes, and snippets.

@nikolaykrylov
Last active February 18, 2017 20:01
Show Gist options
  • Save nikolaykrylov/9784c6be2b8622842a9cc262fbd4f784 to your computer and use it in GitHub Desktop.
Save nikolaykrylov/9784c6be2b8622842a9cc262fbd4f784 to your computer and use it in GitHub Desktop.
Write from form to database
<?php
require 'login.php';
$con = mysqli_connect($db_hostname, $db_username, $db_password, $db_database);
mysqli_set_charset($con, "utf8");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL:" . mysqli_connect_error();
}
<?php
require 'connect.php';
if (isset($_POST['name']) &&
isset($_POST['surname'])) {
$name = $_POST['name'];
$surname = $_POST['surname'];
$query = "INSERT INTO `mytable1` VALUES (NULL, '$name', '$surname');";
$info = mysqli_query($con, $query);
}
?>
<html>
<head>
<meta charset = "utf-8">
</head>
<body>
<form method="POST" action="form2.php">
<input name="name" type="text" placeholder="Имя"/>
<input name="surname" type="text" placeholder="Фамилия"/>
<input type="submit" value="Отправить"/>
</form>
</body>
</html>
<?php
$db_hostname = 'localhost';
$db_database = 'mydb1';
$db_username = 'root';
$db_password = '';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment