Data is not added to the database table via the form when sending the form writes:

echo "<p>Вы ввели не всю информацию, поэтому страница в базу не может быть добавлена.</p>"; <form name="form1" method="post" action="add_lesson.php"> <label>Ввеcти название страницы <br> <input type="text" name="title" id="title"> </label> </p> <p> <label>Ввеcти краткое описание страницы<br> <input type="text" name="meta_d" id="meta_d"> </label> </p> <p> <label>Ввеcти ключевые слова для страницы<br> <input type="text" name="meta_k" id="meta_k"> </label> </p> <p> <label>Ввеcти Дату<br> <input type="text" name="date" id="date"> </label> </p> </p> <p><label>Ввеcти описание страницы с тегами<br> <textarea name="description" id="description" cols="50" rows="10"></textarea> </label></p> <p><label>Ввеcти полный текст страницы с тегами<br> <textarea name="text" id="text" cols="50" rows="10"></textarea> </label></p> <p> <label>Ввеcти Автора урока<br> <input type="text" name="autor" id="autor"> </label> </p> <p> <label> <input type="submit" name="submit" id="submit" value="Занести данные страницы в базу"> </label> </p> </form> 

HERE CODE HANDLE

 <?php include ("blocks/bd.php"); if ($title == ' ') {unset($title);} if ($meta_d == ' ') {unset($meta_d);} if ($meta_k == ' ') {unset($meta_k);} if ($text == ' ') {unset($date);} if ($text == ' ') {unset($description);} if ($text == ' ') {unset($text);} if ($text == ' ') {unset($autor);} ?> <?php if (isset ($title) && isset ($meta_d) && isset ($meta_k) && isset ($date) && isset ($description) && isset ($text) && isset ($autor)) { $result = mysql_query ("INSERT INTO new (title,meta_d,meta_k,date,description,text,autor) VALUES (`$title`,`$meta_d`,`$meta_k`,`$date`,'$description`,`$text`,`$autor`)"); if ($result == 'true') {echo "<p>Ваша страница успешно добавлена!</p>";} else {echo "<p>Ваша страница не добавлена!</p>";} } else { echo "<p>Вы ввели не всю информацию, поэтому страница в базу не может быть добавлена.</p>"; } ?> 

Tell me what to do, I have already tried various options that I found on the network, and put apostrophes, and single quotes do not help quotes ........ (((

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

3 answers 3

The data transmitted by the POST method can be obtained in php using $ _POST ['field name']. For example, the value of a field named title:

 <input type="text" name="title" id="title"> 

can be obtained as $ _POST ['title']. Ready handler code:

 <?php include ("blocks/bd.php"); $title = $_POST['title']; if($title == ' ' or empty($title)){ echo "<p>Вы не ввели название</p>"; } else{ $meta_d = $_POST['meta_d']; if($meta_d == ' ' or empty($meta_d)){ echo "<p>Вы не ввели краткое описание</p>"; } else{ $meta_k = $_POST['meta_k']; if($meta_k == ' ' or empty($meta_k)){ echo "<p>Вы не ввели ключевые слова</p>"; } else{ $text = $_POST['text']; if($text == ' ' or empty($text)){ echo "<p>Вы не ввели текст</p>"; } else{ $date = $_POST['date']; $date = $_POST['description']; $date = $_POST['author']; if(mysql_query ("INSERT INTO new (title,meta_d,meta_k,date,description,text,autor) VALUES (`$title`,`$meta_d`,`$meta_k`,`$date`,`$description`,`$text`,`$autor`)")){ echo "<p>Ваша страница успешно добавлена!</p>"; } else{ echo "<p>Не удалось добавить страницу</p>"; } } } } } ?> 

PS and in your SQL query before $ description there is a single quote "instead of` `

    I use this option

     <?php $response = array(); if (isset($_POST['param1']) && isset($_POST['param2']) && isset($_POST['param3']) && isset($_POST['param4'])) { $param1 = $_POST['param1']; $param2 = $_POST['param2']; $param3 = $_POST['param3']; $param4 = $_POST['param4']; require 'db_connect.php'; $db = new DB_CONNECT(); $result = mysql_query("INSERT INTO objects(param1, param2, param3, param4) VALUES('$param1', '$param2', '$param3', '$param4')"); if ($result) { $response["success"] = 1; $response["message"] = "Object successfully created."; echo json_encode($response); } else { $response["success"] = 0; $response["message"] = "Oops! An error occurred."; echo json_encode($response); } } else { $response["success"] = 0; $response["message"] = "Required field(s) is missing"; echo json_encode($response); } ?> 

      So you are trying to add null.

      Your data comes with a post array, respectively, your $ title, $ meda_d <$ meta_k variables must first be aligned to the corresponding elements of the $ _POST array.

      In addition, several elements of the same name can rub each other.