N
N
N!crO2018-02-19 21:25:52
PHP
N!crO, 2018-02-19 21:25:52

How to write data from input to MySQL?

(function (){

  var sendData = function () {
    var data = new FormData(firstForm);
    var xhr = new XMLHttpRequest();
  
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4 && xhr.status === 200) {
        console.log(xhr.response);
      }
    };
  
    xhr.open('POST', 'data.php');
    xhr.send(data);
  };

  window.backend = {
    send: sendData
  }

})();

<?php

$db_host = "192.168.1.4"; 
$db_user = "n1cro";
$db_password = "XRT6IPLkeK5DyYzc";
$db_name = "invitation";

$link = mysqli_connect($db_host, $db_user, $db_password, $db_name)
   or die("Ошибка " . mysqli_error($link));

mysql_query("INSERT INTO 'users' ('firstname', 'lastname') 
   VALUES (' ".$_POST['firstname']." ',' ".$_POST['lastname']." ')");

mysql_close();

Here are the errors in the browser console:
Warning : mysql_query(): in D:\OSPanel\domains\invitation\build\data.php on line 20
Warning : mysql_query(): A link to the server could not be established in D:\ OSPanel\domains\invitation\build\data.php on line 20
Warning : mysql_close(): no MySQL-Link resource supplied in D:\OSPanel\domains\invitation\build\data.php on line 22

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
doublench21, 2018-02-19
@n1croo

The comment to the dude above is just out loud)))
mysql_query --> mysqli_query
mysql_close --> mysqli_close
and everything will be a bundle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question