Self-learning-begging for database problems

Source: Internet
Author: User
Self-Study-beg you for questions about the database $ link = mysql_connect ('2017. 0.0.1: 100', 'root', '123 ');
If (! $ Link ){
Die ('could not connect: '. mysql_error ());
}


Mysql_select_db ("stu") or die (mysql_error ());
Mysql_query ("set name UTF-8 ");
$ Name = $ _ POST ['name'];
$ Age = $ _ POST ['age'];
$ Aihao = $ _ POST ['aihao'];
$ SQL = "insert into student (u_name, u_age, u_xq) value ('$ name',' $ age', '$ aihao ')";


$ Res = mysql_query ($ SQL, $ link) or die (mysql_error ());
Mysql_free_result ($ res) or die (mysql_error ());

Mysql_close ($ link );
Echo "chenggong". $ res;



The above is the code why Warning: mysql_free_result (): supplied argument is not a valid MySQL result resource in F: \ PHPnow-1.5.6 \ htdocs \ stu \ addok. php on line 18
This problem

If the database connection is successful, you can print the SQL statement and execute it in the database. why is this always so wrong?


Reply to discussion (solution)

The database cannot be written. Only SQL statements can be printed and executed in the database.

Mysql_free_result () is called only when considering how much memory will be occupied when a large result set is returned. After the script is completed, all associated memory will be automatically released.

The insert command does not return the result set. Therefore, the release of the result set does not exist.

Potential problems:
1. mysql_query ("set name UTF-8 ");
MySQL only has utf8 and does not have UTF-8
2. $ SQL = "insert into student (u_name, u_age, u_xq) value ('$ name',' $ age', '$ aihao ')";
Only values does not have value

Thank you, bro.
I changed it. You still cannot write it in.

Insert into student (u_name, u_age, u_xq) values ('ee ', '22', '123 ')
Warning: mysql_free_result (): supplied argument is not a valid MySQL result resource in F: \ PHPnow-1.5.6 \ htdocs \ stu \ addok. php on line 20
Is it a problem with database restart or installation configuration?

Again!
Executing the insert (update, delete, etc.) command only returns the logical value to indicate whether the execution is successful.
No result set is returned, so it is not released.

Thank you!

Free has already cleared the result set and can be called again .. Can this problem be avoided ..

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.