Answer the question
In order to leave comments, you need to log in
Why doesn't insert into work with php?
Hello. I'm trying to write data to the database through php, but the record is not added. Please tell me what is wrong.
html form:
<form method="POST" action="<?=$_SERVER['REQUEST_URI']?>">
<input name="title" type="text" placeholder="Заголовок"/>
<input name="intro" type="text" placeholder="Краткое описание"/>
<input name="full" type="text" placeholder="Полный текст"/>
<input type="submit" value="Отправить"/>
</form>
if (isset($_POST['title']) && isset($_POST['intro']) && isset($_POST['full']))
{
// Переменные с формы
$title = $_POST['title'];
$intro = $_POST['intro'];
$full = $_POST['full'];
// Параметры для подключения
$db_host = "localhost";
$db_user = "login"; // Логин БД
$db_password = "password"; // Пароль БД
$db_table = "articles"; // Имя Таблицы БД
// Подключение к базе данных
$mysqli = new mysqli("localhost", "login", "password", "articles");
$query = "INSERT INTO articles (title, intro, full) VALUES ('$title','$intro', '$full')";
$mysqli->query($query);
}
$db_table = "articles";
$mysqli = new mysqli("localhost", "login", "password", "articles");
"INSERT INTO articles
Answer the question
In order to leave comments, you need to log in
$db_table = "articles"; // Database table name
No, not the table name, but the database name ( $dbname ).
if (!$mysqli->query($query)) { printf("Errormessage: %s\n", $mysqli->error); }
See also: SQL Injection
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question