We bring the data in the database through the form. Those. in one file I create an input form,
and by $ _post I send to another file where the code for inserting the data entered in the database is. Swears just at that very main line, which inserted and responds.
$ result = mysqli_query ("Insert Into Firma ('Name', 'Surname', 'Doljnost') Values ('$ Name ',' $ Surname ',' $ Doljnost ') ");
Writes: Warning: Mysqli_Query () Experts at Least 2 Parameters, 1 Given in Z: \ Home \ Localhost \ www \ php \ mysql_insert2.php on line 38
This is such a “piece” infeaving in the file that sends data in the database.
& lt;? php
$ link = mysqli_connect ('Localhost', 'alex', '12345', 'firstbd');
/ * Connection check * /
if (mysqli_connect_errno ()) {
PrintF ("Failed to connect:% s \ n", mysqli_connect_error ());
exit ();
}
/ * Changing the set of characters on UTF8 * /
mysqli_set_charset ($ Link, "UTF8");
If (ISset ($ _ post ['name']))
{
$ name = $ _post ['name'];
}
if (ISset ($ _ post ['surname']))
{
$ SURNAME = $ _Post ['Surname'];
}
if (ISset ($ _ post ['doljnost']))
{
$ doljnost = $ _post ['doljnost'];
}
$ result = mysqli_query ("Insert Into Firma ('Name', 'Surname', 'Doljnost') Values ('$ Name', '$ Surname', '$ Doljnost')");
if ($ result == TRUE)
{
Echo "& lt; br & gt; information in the database is added successful.";
}
Else Echo "& lt; br & gt; information in the database is not added.";
mysqli_close ($ Link);
? & gt;
Answer 1, Authority 100%
This is the documentation: mysqli_query ()
. In procedural style, the function takes two parameters: the connection identifier and request.
Thus, it is worth writing like this:
$ query = "Insert Into Firma (` name`, `Surname`,` doljnost`) Values ('$ Name' , '$ SURNAME', '$ Doljnost') ";
$ result = mysqli_query ($ Link, $ Query); // Key Point - First Parameter
that incoming data can not be substituted without processing you, I hope you know.
The databases are allocated inverse , and not ordinary apostrophe, i.e. `Instead ‘
To find out what happened, use mysqli_error () . Instead of “Information to the database not added” Write:
echo mysqli_error ($ Link);
Answer 2, Authority 67%
and should not be so?
$ result = mysqli_query ($ Link, "Insert Into Firma ('name', 'Surname', 'Doljnost') Values ('". $ Name."', '". $ Surname."', '". $ Doljnost."') "); // Updated! Now stand up :)
It seems to add a link to the connection to the database … or I’m wrong?
// PS As long as Edelweiss answered it faster: (