Menu
Is free
check in
home  /  Firmware / Add an entry to the SQL PHP table. Adding data to PHP

Adding an entry to the SQL PHP table. Adding data to PHP

All site modules or web applications where you need to make and write down some data (for example, name, age, address, etc.) use simple function in the language of MySQL Insert Into` Name_Base` (Name, Value1, Value2) Values \u200b\u200b('Vasya ',' 1 ',' 2 ');

All variables are brought into the database according to the values \u200b\u200bthat we specified in the first brackets. It is important to consider the encoding of the processor script, database and configuration file. It is desirable to use the most common UTF-8 encoding.

It should be borne in mind that you can record in the database in two ways.

First method If we do not specify the initial names of the database tables. Then we must list all the variables for each cell, namely how many cells in the database table, so many variables must be listed in brackets after Value.

For example:
In the database table, four cells. So after the Value element (..), all four variables must be listed in brackets. And one more point: if the variable does not exist, let's say this is an optional parameter. Then we write just an empty value in quotes '',

"INSERT INTO` name_base` Values \u200b\u200b(NULL, `". $ Name. "`, ``, `2`)"; // third empty meaning is written in quotes

But this request has small flaws. If you add one cell or two cells to the database table, then this request will return the error. Because in this method, the listing of all cells in the query is required.

Second way If after the query INSERT INTO `name_base` (...) list all the cells after the name of the database. An example is already considered slightly higher. If you forgot, write a re-:

"INSERT INTO` name_base` (`name`,` Value`, `Value2`) Values \u200b\u200b(NULL,` ". $ Name." `,` `,` 2`) ";

Here we listed all cells (Name, Value1, Value2). And if you add additional two cells to the database table, the query syntax should not be changed. But if we do not need to add at once in one request, the most advanced variables that we need for those newly created cells are.

This error flies very often, after a small change on the site. Suppose the administrator added an additional cell to the database, let's say Status. And the script handler did not have time to change the module, or just forgot it elementary. But some sites have a very complex structure, and a lot of time and effort can go to the error search. Therefore, it is desirable to use the second method of recording to the database. Although this kind of mistakes more often allow novice web programmers.

PHP recording to the MySQL database. Practical examples

So, now we got to the very essence when working with database queries. Everybody will do on practical examples. Create a simple script to record comments that will leave visitors to the site.

To begin with, create a MSG table in a four-cell database. In the first cell writing a comment ID. The number of characters in a cell is up to ten characters with the Auto-Increment parameter. it automatic parameter It will change every time the comment is +1.

Next Name Cell Username. The number of characters - to two hundred - three hundred characters to your choice, the char parameter. The COMENT cell is then to make the comment text itself in this cell. If you want to record large texts of comments, you can set the TEXT parameter - then you can simply enters the huge texts, more than five hundred thousand characters or set the TinyText parameter, then it will take a little less than characters, but it will work a little faster.

But in our case, we will keep in mind that visitors will not write huge texts. And therefore, we will restrict ourselves and will fix two thousand characters with the Varchar parameter, to record string values.

In the last cell we will write the date of making a comment text recording. We will write in a numeric format in seconds, using the current date and time function Time (); For simplicity, the function will set the $ TIME \u003d TIME () to the variable; And create a cell in the database. We call the TIME name with the int parameter (for numerical values). I prophesy the number of characters is better eleven (with a small reserve for the future :-).

Dump database Next:

Structure of Table `MSG` MSG Create Table (` Int (10) Not Null Auto_Increment, `Name` CHAR (250) Not Null,` COMENT` VARCHAR (2000) Not Null, `time` int (11) Not Null, Primary Key (`id`)) Engine \u003d Myisam Default Charset \u003d UTF8 AUTO_INCREMENT \u003d 1;

Everything, the table for comments created. Now we write a form to write a comment and myself script handler. HTML -Code forms to enter a comment Next.

In this article we will discern, perhaps, one of the most important SQL queries. it requests for adding and deleting records from the database table. Since, very often has add new entries to the tableAnd to do it in automatic mode, then this material is required to be learning.

To start SQL request for adding new recording in Table:

INSERT INTO USERS (LOGIN, PASS) VALUES ("TestUser", "123456")

When adding an entry, the team comes at the beginning. " INSERT INTO", Then the name of the table in which we insert the record. Next goes to the heads of the fields, which we want to fill. And then in parentheses after the word" values."We start listed the values \u200b\u200bof those fields that we have chosen. After executing this request, a new entry will appear in our table.

Sometimes required refresh entry in the tablefor this there is the following SQL request:

Update Users Set Login \u003d "TestUser2", pass \u003d "1234560" WHERE LOGIN \u003d "TestUser"

This request is more difficult, as it has a design " Where", but about it just below. At first there is a team" Update.", then the name of the table, and after" SET."We describe the values \u200b\u200bof all the fields that we want to change. It would be simple, but the question arises:" What kind of recording should be updated?". For this exists" Where"In this case, we update the entry, the field" login."Which is important" Testuser.". Please note that if there are several such records, then absolutely everything will be updated! It is very important to understand, otherwise you risk losing your table.

Let's talk a little about " Where"In addition to simple checks on equality there are also inequalities, as well as logical operations: And. and Or..

Update Users Set Login \u003d "TestUser2", Pass \u003d "1234560" WHERE ID< 15 AND login="TestUser"

The SQL request Update those records id which are less 15 AND field " login." has the meaning " Testuser."I hope you dealt with the design" Where", Because it is very important. It is" Where"Used by sampling records from tablesAnd this is the most part-to-use task when working with databases.

And, finally, simple SQL request to delete records from the table:

Delete from Users WHERE LOGIN \u003d "TestUser2"

After the team " Delete from."There is a name of the table in which you want to delete records. Then describe the" WHERE "design. If the record will comply with the conditions described, it will be deleted. Again, pay attention, depending on the number of records that satisfy the condition after" Where", Any amount of their number can be deleted.

In this guide, you will get acquainted with how to start governing the database from your Php.script. You will explore adding an entry to the MYSQL table,using Php code. Before starting, read our other manuals that reveal the main steps of working with PHP and databases - connect from PHP to the MySQL database (English).

Before you start, check the presence of the following:

  • Access to your Hosting Control Panel

Step 1 - Creating a Table

First of all, we need to create a table for your data. This is very simple procedurewhich you can do in phpmyAdmin. From your hosting control panel. We have already described the MYSQL database process in the previous manual (English), so we will skip this moment here.

After logging into PHPMYAdmin, you will see a similar picture:

Create a table titled Students. For our database u266072517_Name.. Create a new table can be called Create Table. After that you will see new pagewhere you can enter all the necessary data for your table:

This is the easiest way to create a table, for more information about the structure of the table / database and which settings can be used for each field, refer to the formal PHPMYAdmin documentation (English).

Here are a few simple explanation of the fields that we will use:

  • Name. - This is the name of your field. It will be displayed at the top of your table.
  • Type - You can set the field type here. For example, we choose varchar.because here we need to enter a string with the name (in which there are letters, not numbers).
  • Length / Values. - Used to set the maximum length of your entry in this field.
  • Index. - We use the PRIMARY index for our field "ID". When a table is created, it is recommended to have one ID field. It is used to index records in the table when the relationships are configured between the tables. It can also be noted here "A_i"What means AUTO INCREMENT.. This setting will automatically increase the index (1,2,3,4 ...).

Click Save. And your table will be created.

Step 2 - Create PHP code and add an entry to the MYSQL table

Option 1 - Mysqli method

First of all, you need to establish a database connection, according to our previous management. After that, we can continue with SQL request to add an entry to the MYSQL table - Insert.. Here is a complete sample code with connecting and insertion method:

". mysqli_error ($ Conn);) Mysqli_Close ($ Conn);?\u003e

Thus, the first part of the code (string 3 – 18 ) Refines part of the establishment of a connection to the database. We will not re-pass through this part if you want to know what each string means, refer to our previous management how to connect to the database (English).

Let's start with the line 19 :

$ SQL \u003d "INSERT INTO STUDENTS (Name, Lastname, Email) Values \u200b\u200b(" Thom "," Vial "," [Email Protected]")";

This is the most important line of the code, it does everything about as we describe in this manual - adding an entry to the MySQL table to the database. INSERT INTO - This is an expression that adds an entry to the specified MYSQL database table. In our example, we add data to the table Students..

Moving on, in brackets, we define the table fields, the values \u200b\u200bin which we will add: (Name, Lastname, Email). Data will be added in a definable. If we write (Email, LastName, Name)The values \u200b\u200bwill be added in a different order.

Next part of the value Values.. Here we ask our values \u200b\u200bin previously specified fields. Thus, each field will get its value. For example, in our case, it will be something like: name \u003d Thom, LastName \u003d Vial, email \u003d [Email Protected] .

What is important to note that we form sQL requestUsing PHP code. SQL requests must be enclosed in quotes. In our example, everything is between quotes and walking after $ sql \u003d this is a SQL query.

Next part of the code ( 20 – 22 Strings) Runs our request and verify the success of the query execution:

If (Mysqli_Query ($ Conn, $ SQL)) (Echo "New Record Created SuccessFully";)

A message about good luck is displayed if the request has been running correctly.

And the final part ( 22 – 24 Lines) show another message, in case of unsuccessful execution of our request:

ELSE (Echo "error:". $ SQL. "
". mysqli_error ($ Conn);)

This code displays a message about the error, in case something went wrong.

Option 2 - PHP data object method (P HP D ATA O BJECT)

As in the previous example, we first need to connect to the database, which is performed when creating a new PDO object - the previous guide tells about how it happens. Since the connection to the MySQL database is a PDO object, we must use different PDO 'methods' (a kind of functions that are part of a specific object) to prepare and start a query. Methods of objects are caused in this way:

$ The_object-\u003e The_Method ();

PDO allows you to "prepare 'SQL code before its execution. SQL request It is calculated and adjusted before starting. So, a simple attack by SQL Injection Filling SQL code can be performed in the form field. For example:

// User Writes this in the username field of a login form thom "; drop database user_table; // The Final Query Becomes this" Select * from user_table where username \u003d thom "; drop database user_table;

Since SQL code is syntactically correct, a point with a comma makes Drop Database User_Table New SQL query, and your user table has been removed. Preparing expressions do not allow symbols and ; To complete the source request, and instructions DROP DATABASE. Never execute.

Is always Use the prepared queries when you send or receive data from the database with PDO.

To use the prepared expressions, you need to create a new variable that will cause method prepare () At the database object.

In the correct form, the code looks like:

$ servername \u003d "mysql.hostinger.com"; $ Database \u003d "U266072517_Name"; $ username \u003d "u266072517_user"; $ password \u003d "buystuffpwd"; $ SQL \u003d "MySQL: Host \u003d $ servername; dbname \u003d $ database;"; $ dsn_options \u003d; // CREATE A NEW Connection to the Mysql Database using Pdo, $ My_DB_Connection IS An Object Try ($ My_db_Connection \u003d New PDO ($ SQL, $ Username, $ Password, $ dsn_options); echo "Connected SuccessFully";) Catch (PDOException $ Error) (Echo "Connection Error:". $ error-\u003e getMessage ();) // Set the Variables for the Database $ first_name \u003d "thom"; $ last_name \u003d "vial"; $ email \u003d " [Email Protected]"; // Here WE CREATE A VARIABLE THAT CALLS THE PREPARE () METHOD OF THE DATABASE OBJECT // THE SQL QUERY YOU WANT TO RUN IS ENERGED AS THE PARAMETER, AND PLACEHOLDERS ARE WRITTEN LIKE THIS: PLACEHOLDER_NAME $ MY_INSERT_STATEMENT \u003d $ MY_DB_CONNECTION-\u003e Prepare ("INSERT INTO STUDENTS (Name, Lastname, Email) Values \u200b\u200b(: first_name,: last_name,: email)"); // NOW WE TELL THE SCRIPT WHICH VARIABLE EACH PLACEHOLDER ACTUALLY REFERS TO USING THE BINDPARAM () METHOD // FIRST parameter is the placeholder in the statement above - the second parameter is a variable that it should refer to $ my_Insert_Statement-\u003e bindParam (: first_name, $ first_Name); $ my_Insert_Statement-\u003e bindParam (: last_name, $ last_Name); $ my_Insert_Statement-\u003e BindParam (: Email, $ email); // Execute The Query using the Data We Just Defined // The Execute () Method Returns True If It Is Successful and False If It Is Not, Allowing You to Write Your Own Messages Here If ( $ MY_INSERT_STATEMENT-\u003e EXECUTE ()) (Echo "New Record Created SuccessFully";) EL SE (Echo "Unable to Create Record"; ) // At this Point You Can Change the Data of the Variables and Execute Again to Add More Data to the Database $ first_name \u003d "John"; $ last_name \u003d "smith"; $ email \u003d " [Email Protected]"; $ MY_INSERT_STATEMENT-\u003e EXECUTE (); // Execute Again Now That The Variables Have Changed If ($ My_insert_statement-\u003e Execute ()) (Echo" New Record Created SuccessFully ";) Else (Echo" Unable to Create Record "; )

In lines 28, 29 and 30, we use the method bindparam () Database object. There is also a method bINDVALUE ()different from the previous one.

  • bindparam () -this method counts the data when the method execute () achieved. The first time the script comes to the method execute () He sees that $ first_name. refers to "Thom", connects this value and fulfills the request. When the script gets the second time before the method execute ()he looks like $ first_name. Now refers to "John", connects this value and launches a request again with a new value. It is important to understand that we create a request once and then substitute different data in different sections of the script.
  • bINDVALUE () -this method calculates data as soon as the queue comes to it. As the value $ first_name. was asked as "thom" at the time when we reached the method bINDVALUE ()it will be used when calling the method Execute () for $ MY_INSERT_STATEMENT..

Note that we re-use the variable $ first_name. And we ask her a new value for the second time. If you check your database after starting this script, there will be both of the specified name, contrary to this value of the variable $ first_name.it will be "John" at the end of this script. Remember that PHP estimates the contents of the script before starting it.

If you change your script replacing bindparam. on the bindvalue.You will add the "Thom Vial" to the MysQL database twice to the database and John Smith will be ignored.

Step 3 - Check the success of fulfillment and solving general issues

If the query that we launched in the MySQL database was successful, we will see such a message:

Solving common mistakes

Mysqli.

In any other case, an error message will be displayed instead of the message. For example, let's say one syntactic error in our code and we will get this:

As we see, the first part of the code is in order, the connection was successfully installed, but our SQL query has collided with failure.

"Error: INSERT INTO STUDENTS (Name, Lastname, Email) Values \u200b\u200b(" Thom "," Vial "," [Email Protected]") You have An Error in Your SQL Syntax; Check The Manual That CorreSponds to Your Mysql Server Version for the Right Syntax To Use Near" (Name, Lastname, Email) Values \u200b\u200b("Thom", "Vial", " [Email Protected]")" AT LINE 1 "

A syntax error is allowed that fails in the execution of our script. The error was here:

$ SQL \u003d "INSERT INTO STUDENTS (Name, Lastname, Email) Values \u200b\u200b(" Thom "," Vial "," [Email Protected]ome.com ")";

As you can see, we use curly braces instead of round. It is incorrect and leads to a syntactic error in our script.

Pdo

In the PDO connection line 7, the error handling mode is set to 'Display All Exceptions' (display all exceptions). If you remove it from the script and the request will fail, you will not receive any error message. With the exceptions enabled, specific problems arising will be displayed. Basically it is better to use when you develop a script, as this can identify the names of databases and tables that you would like to hide from anyone who can get unauthorized access to your data. In the case above, when the curly brackets were used instead of round, the error looks like shown below:

FATAL ERROR: UNCAGHT EXCEPTION "PDOEXCEPTION" WITH MESSAGE "SQLSTATE: SYNTAX ERROR OR ACCESS VIOLATION: 1064 YOU HAVE AN ERROR IN YOUR SQL SYNTAX; check The MANUAL THAT CORRESPONDS TO Your Mysql Server Version for the Right Syntax to Use Near "(Name, Lastname, Email) Values \u200b\u200b(" Thom "," Vial "," [Email Protected]")" AT LINE 1 "

Other problems with which you may encounter:

  • Incorrectly specified fields (non-existent fields or errors in writing titles).
  • Malconformity of the type of field type. For example, when we want to assign the value of the number 47 Field Name.We will get a mistake because it is assumed that the value will be a string. But if you specify a number in quotes, for example, “47” , There will be no errors, because our number will be recorded as a string in this field.
  • An attempt to enter data into a table that does not exist or an error in writing the table name.

All these errors can be corrected following error correction manuals or checking the error log (English).

After successfully adding data, we must see them in our database. Here is an example of a table in which we added our data if you look at phpmyAdmin..

Conclusion

In this guide, you studied how to use PHP code to add an entry to the MYSQL tableusing Mysqli. and Pdo. Also reviewed cases of common errors and solutions. Knowing how to use PHP code to add to the MySQL database is useful regardless of whether you learn to program or already create your website.

In this post I want to tell how to transfer to the database, entered data in the form. And so we create simple shapewhere we will have two fields: username and it email:

Your name:
Your e-mail:


This form can be applied to register a new user, to send news, to collect statistics, yes for anything ... In general, the user scores its data to this form: the name and mail, clicks on the button and then the data goes into the PHP script:

$ name \u003d $ _post ["Name"]; $ email \u003d $ _post ["email"]; $ result \u003d mysqli_query ("INSERT INTO User (Name, Email) Values \u200b\u200b(" $ Name "," $ email ")"); If ($ result) (Echo "data is successfully saved!";) ELSE (ECHO "occurred, please repeat the attempt.";)


What is happening in this script? Now will figure it out!
Entered into data pOST Go to PHP script (which is written above), and with the global array $ _POST data is formed into variables $ Name and $ Email:

$ name \u003d $ _post ["Name"]; $ email \u003d $ _post ["email"];


After the variables are ready for enhancing to the database, make up a request. But before your scripts must be already connected to the database, how to connect to the database, I wrote in this thread :. The request itself looks like this:

$ result \u003d mysqli_query ("INSERT INTO User (Name, Email) Values \u200b\u200b(" $ Name "," $ email ")");


In this code, we denied that in the Name and Email cells that are in the User table, the following variables will be added: $ Name and $ email.
Next, if everything went successfully, we will receive a message from the condition:

Data successfully saved!


If any problems arose and the data was not listed, we will receive an error message:

An error occurred, please repeat the attempt.


That's all!

*** *** *** *** ***

If you wish, you can add more fields to enter information, for example, we need to add a field to enter the city's city. We already have a ready-made script (written above), now just add the field Your town, Call variable: $ city. And so in the form of data entry, after:

Your e-mail:


we add:

Your town:


In PHP script, after:

$ email \u003d $ _post ["email"];


we add:

$ City \u003d $ _Post ["City"];


Well, of course add in the query too, like this:

$ result \u003d mysqli_query ("INSERT INTO User (Name, Email, City) Values \u200b\u200b(" $ Name "," $ email "," $ city ")");


Here, what should happen in the end:
Input form:

Your name:
Your e-mail:
Your town:


Script:

$ name \u003d $ _post ["Name"]; $ email \u003d $ _post ["email"]; $ City \u003d $ _Post ["City"]; $ result \u003d mysqli_query ("INSERT INTO User (Name, Email, City) Values \u200b\u200b(" $ Name "," $ email "," $ city ")"); If ($ result \u003d\u003d true) (ECHO "Data Successfully saved!";) ELSE (ECHO "occurred, please repeat the attempt.";)


As you can see anything difficult! If necessary, you can add another field, and more, and more ...

Comments transferred from blog

SERGEI
09/14/2016 at 01:25
Good afternoon!
Interested in such a question: how to easily organize data storage and program settings without using the database? I do not want to get tied to MySQL or Access ..

Admin.
09/14/2016 at 22:14
Hello!

Properties.settings.
App.config
XML file.
Serialization
Try to choose something from this from the list.

Nikolai
09/16/2016 at 02:28.
Hello, how to remove the selected string in DataGridView from DataGridView and PhpmyAdmin.

PhpmyAdmin? This is just a shell to work with the database, can you explain?

Nikolai
09/18/2016 at 02:24
It is necessary that the dedicated string would be removed from DataGridView and from the database.

Admin.
09/19/2016 at 07:00
How to remove a string in the database mySQL data - Added an article.

Nikolai
09/20/2016 at 09:20
Thanks a lot.

DIMA
09/20/2016 at 10:24
Hello, can this method Implement not through DataGridView, but through ComboBox? If so, how? Thanks.

Admin.
09/22/2016 at 03:21
Hello. Example:

Gennady
09/22/2016 at 18:25
Why should I enter the database of System.Windows.Forms.TextBox, Text: Ge

To the stack, this (ge) to the end it is written the gene. At least in the table settings, the text is specified. The genet should be fit further. I bring this table to my program and it turns out that it displays me all this unnecessary text.

Admin.
09/24/2016 at 04:17.
Most likely, the SQL query is incorrectly written, for example:

In TextBox1 I enter a name: gene.

SQL query: "INSERT INTO Name Table Values \u200b\u200b(TextBox1, ..)"; Result: System.Windows.Forms.TextBox.

And you need to transmit: "Insert Into The name of the Values \u200b\u200btable (textbox1.text, ..)";
Result: Gena

Gennady
09/24/2016 at 18:41
That is how it is. Thanks

SERGEI
09/25/2016 at 11:51
Hello. And how to implement adding to database via TextBox?

Admin.
09/26/2016 at 20:53
All the same in principle. For example, take the latest example, you need:

// Create parameters and add them to the CMD.parameters.AdDWithValue collection ("@ name", textbox1.text); cmd.parameters.addwithvalue ("@ LastName", textbox2.text);

now Parameters: Name and LastName Get values \u200b\u200bentered in TextBox-s and transmit them to the database

Linara
09/27/2016 at 17:45.
Hello, how are the selected string in DataGridView and phpMyadmin?

Admin.
09/29/2016 at 02:06.
I do not know how you can highlighted the line in phpmyAdmin. And in DataGridView, for example, this can be done using the selectionchanged event.

Psh.
09/30/2016 at 03:48.
2 cable:
If you want to edit the rows so much, take the A la Hedisql tool, configure and change the lines.

2Admin.
Good day! Thanks for the materials - everything is very cool)
Question: I add data to this request (it is test):

String SQL \u003d "Insert Into Users (` Fio`, `Tour`,` count`, `Cost`,` date`, `Passport`,` Birth`) Values \u200b\u200b("Kolyan", "Moscow", "1 + 1 ", 1100," 2011-11-11 "," 1111 1111 "," 9.11.1900 ");";

Data is made all ok, but in the database (mysql) instead of Cyrillic turn out to be "????".

Visual Studio said that System.String is a sequence of Unicode.

Also tried:

Alter Database `Test` Collate" koi8R_GENERAL_CI "; ALTER TABLE `Users` Collate \u003d" koi8r_general_ci "; Alter Database `Test` Collate" UTF8_Unicode_ci "; Alter Table `Users` Collate \u003d" UTF8_Unicode_ci ";

But does not help ..
What can be wrong? Different VS encoding and database? Or what?
Could send that read / change.
thanks

Admin.
10/01/2016 at 09:49.
Hello.

In the database (and in the table), the matching utf_general_ci

Is there such a comparison? Perhaps UTF8_GENERAL_CI?

Usually create a MYSQL database choosing a UTF8_GENERAL_CI comparison, so there are no problems with Cyrillic, unless the client come from the client to the server.

Collation is used for comparison, and in this case the encoding is important (Charset). Therefore, first you need to make sure that it is set on the server correctly, for example in UTF8, and not Latin1.

When you connect through .NET connector (default) used Latin1, so it is sometimes necessary to explicitly specify in the connection string UTF8:

MysqlConnection Mycon; MyCon \u003d New MySqlConnection ("Server \u003d 127.0.0.1; uid \u003d vasya; pwd \u003d 123; database \u003d test; Charset \u003d UTF8;"); // MysqlConnectionStringBuilder: mysqlcsb.characterset \u003d "UTF8";

Psh.
10/01/2016 at 11:34.
You are right, described, UTF8_GENERAL_CI!
Yes helped,; Charset \u003d UTF8;
Thanks OGMNO!

Sergiy.
10/02/2016 at 11:02.
Thanks for the working example, right. Question
I created a text field to which I would like to enter a database address, but I do not know how to substitute this data here

String Constr \u003d " [Email Protected]; User \u003d Test; "+
"Database \u003d Test; password \u003d test;";
Please tell me how to insert data from text fields in Windows Form into this design ....

Admin.
03.10.2016 at 11:50
"[Email Protected]; User \u003d ...
In general, it is better to use the properties in this article as in this article, or the String.Format () method

OLGA2203.
05/15/2017 at 20:14

String Connect \u003d "Server \u003d 127.0.0.1; port \u003d 3306; Database \u003d Base; Data Source \u003d localhost; user \u003d root;"; MySqlConnection CON \u003d New MySqlConnection (Connect); con .Open (); // Install the connection to the database. Mysqlcommand cmd \u003d new mysqlcommand (); cmd.commandText \u003d @ "Insert Into Tovar (ID, Category, Name, Trademark, Price, Photo, Size, Color, Material, Count) Values \u200b\u200b(@pr, @category, @name, @trademark, @price, @photo, @Size, @color, @material, @count) "; cmd.parameters.addwithvalue ("@ PR", Counter); cmd.parameters.addwithvalue ("@ Category", ComboBox1.SelectedItem.Tostring ()); cmd.parameters.addwithvalue ("@ name", textbox1.text); cmd.parameters.addwithvalue ("@ trademark", textbox2.text); cmd.parameters.addwithvalue ("@ Price", convert.toint32 (textbox4.text)); cmd.parameters.addwithvalue ("@ photo", textbox3.text); cmd.parameters.addwithvalue ("@ Size", textbox6.text); cmd.parameters.addwithvalue ("@ color", textbox5.text); cmd.parameters.addwithvalue ("@ Material", textBox8.text); cmd.parameters.addwithvalue ("@ count", convert.toint32 (textbox7.text)); cmd.connection \u003d con; cmd.executenonquery (); MessageBox.Show ("Addition was successful", "Addition was successful", MessageBoxButtons.ok, MessageBoxicon.asterisk);

The error "Column 'ID' Cannot Be Null" is issued, remove the addition of the ID to the column - the same thing about the next column writes, etc.
If you put any constant values \u200b\u200bin brackets in Values, the string is added to the database.
Tell me, please, what's the problem? I need to record data and values \u200b\u200bin the database