H
H
HeartOfProgrammer2015-10-08 18:56:54
PHP
HeartOfProgrammer, 2015-10-08 18:56:54

Why doesn't PHP push content into MySQL database?

I tried to do "Entering content into the database using the POST method", but something did not work out for me. All code compiles without errors, but in MySQL database -> PHPmyAdmin shows nothing in the database. What could it be? Maybe my code is wrong? Or am I not putting the data into the database correctly?
index.php:

<form method="post" action="processing.php">
    Названия<input name="title"><br>
    Описания<input name="first_description"><br>
    Второе описания<input name="second_description"><br>
    Автор<input name="author"><br>
    <input type="submit">
  </form>

processing.php:
$title = $_POST['title'];
    $first_description = $_POST['first_description'];
    $second_description = $_POST['second_description'];
    $author = $_POST['author'];

    $link = mysqli_connect('localhost', 'simple_user', 'qwerty', 'post_method');

    if(!$link) {
      echo "Ошибка подключения базы данных: " . mysqli_error();
    }else {
      echo "Подключения прошла успешно!";
    }

    $sql = "
      INSERT INTO content (title,fisrt_description,second_description,author)
      VALUES($title,$first_description,$second_description,$author)
    ";

    $query = mysqli_query($link,$sql);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivanq, 2015-10-08
@Ivanq

PHP variables in the string are changed to unquoted values ! Need to put

$sql = "INSERT INTO content (title,fisrt_description,second_description,author) VALUES('$title','$first_description','$second_description','$author')";
.
But this is a bad choice. Read more about mysqli_prepare.
By the way, the request needs to be closed $query->close(); Now I don’t remember exactly, maybe I need to add $query->execute();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question