Failed to use the INSERTINTO statement to insert data to the database.

Source: Internet
Author: User
Failed to use the INSERTINTO statement to insert data to the database. Include (conn/conn. php );
If ($ _ POST [submit]) {
$ Code = $ _ POST ['code'];
$ Note = $ _ POST ['note'];
$ Routeway = $ _ POST ['routeway'];
$ Operator = $ _ POST ['operator'];
If ($ code! = "" | $ Note! = "" | $ Routeway! = "" | $ Operator! = ""){
$ SQL = "INSERT INTO code_group (groupNumber, groupCode, groupNote, groupRouteway, groupOperator) VALUES ('', '$ code',' $ note ',' $ routeway ', '$ operator ')";
If (mysql_query ($ SQL )){
Echo "script" alert ('inserted successfully'); script ";
} Else {
Echo "script" alert ('insertion failed'); script ";
}
} Else {
Echo "script" alert ('the content you entered is Null'); script ";
}
}
?>



This is the library settings
Create table 'code _ group '(
'Groupnumber' smallint (6) not null,
'Groupcode' char (8) not null,
'Groupnote' varchar (100) not null,
'Grouprouteway' char (15) not null,
'Groupoperator' char (4) not null,
Primary key ('groupnumber ')
) ENGINE = InnoDB default charset = utf8;

The PHP program can run normally, and the database can be connected normally, that is, the data cannot be inserted. I don't know why.


Reply to discussion (solution)

GroupNumber: a null value is inserted into the primary key.
Run your SQL statement again next time.

Echo mysql_error ();
You can see the cause of the error.

GroupNumber: a null value is inserted into the primary key.
Run your SQL statement again next time.


It is useless to assign a value to the database. the database reports the error "Access denied for user'' @ 'localhost' (using password: NO). However, the database connection password is correct.

Echo mysql_error ();
You can see the cause of the error.


Error: Access denied for user ''@ 'localhost' (using password: NO)
However, the password for connecting to the database is correct and I don't know how to solve this problem.

Access denied for user ''@ 'localhost' (using password: NO)
You do not have a password when connecting.The password for connecting to the database is correct."

Access denied for user ''@ 'localhost' (using password: NO)
You do not have a password when connecting.The password for connecting to the database is correct."


Baidu says that the user name and password do not match. refer to the online method to change the password. I have tried to restart mysql, but I still cannot. Can the moderator tell me how to solve this problem. If there is no problem with the database connection query, the insertion goes wrong.

Thank you for solving the problem.
The problem is that include contains files, include (conn/conn. php); add spaces between include and (conn/conn. php.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.