Y
Y
yDaniil2020-06-29 23:48:58
PHP
yDaniil, 2020-06-29 23:48:58

Why are mysql table values ​​not showing?

Wrote a feedback form. Sending data from to the save_data.php file, from there it connects to the database and saves the data to it. I enter the data in the form, I send. If you go to PhpMyAdmin, table overview - I want to see: a table with data values ​​from forms, I see: flattened lines. The content is not displayed, but each new addition (each form submission) is counted in the table row counter. What am I doing wrong?5efa528a2d8e4886341404.png

<form>
      <input type="email" id="email" name="email" placeholder="Введите ваш Email" class="form-control"><br>
      <input type="text" id="name" name="name" placeholder="Введите имя" class="form-control"><br>
      <input type="phone" id="phone" name="phone" placeholder="Введите телефон" class="form-control"><br>
      <textarea name="message" id="message" placeholder="Ваше сообщение" class="form-control"></textarea><br>
      <button type="button" id="Send" class="btn btn-success">Отправить</button>
    </form>


$("#Send").on("click", function(){
  var email = $("#email").val().trim();
  var name = $("#name").val().trim();
  var phone = $("#phone").val().trim();
  var message = $("#message").val().trim();

  $.ajax({
    url: 'php/save_data.php',
    type: 'Post',
    cache: false,
    data: {'name': name,'email': email,'phone': phone,'message': message},
    dataType: 'html',
    beforeSend: function() {
   		$("#Send").prop("disabled",true)
    },
    success: function(data) {
      alert(data);
    $("#Send").prop("disabled",false)
    }
  });
});


<?php
    // получаем данные от js
    $email = $_Post['email'];
    $name = $_Post['name'];
    $phone = $_Post['phone'];
    $message = $_Post['message'];

  // параметры подключения
  require_once 'settings.php';

  // создаем подключение
  $link = mysqli_connect($host, $user, $password, $database);
    if (!$link) {
        echo "Ошибка: Невозможно установить соединение с MySQL." . PHP_EOL;
        echo "Код ошибки errno: " . mysqli_connect_errno() . PHP_EOL;
        echo "Текст ошибки error: " . mysqli_connect_error() . PHP_EOL;
        exit;
  }
   
  // выполняем операции с базой данных
       
  $query = "INSERT INTO `message` (`name`, `email`, `phone`, `message`)
  VALUES('{$name}', '{$email}', '{$phone}', '{$message}')";

   if(mysqli_query($link, $query))
            {
                  echo "Запись добавлена!";
             }
  // закрываем подключение
  mysqli_close($link);
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-06-29
@yDaniel

$_POST !== $_Post
In PHP, variable names are case sensitive.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question