About PHP database update

Source: Internet
Author: User
Tags php database php file editor
The PHP database update Post was last edited by UR_Not_Alone at 11:55:36

At the beginning, I encountered some basic questions about PHP. please help me.
I read an example from the internet and did some exercises.
When I fill in the page content and click submit, insert. php is opened by default on the page, instead of executing the insert. php code to insert the database.
The code is as follows:
Html page
 Untitled Document


Insert. php
 0) echo "xinwentianjiachenggong!";?>
 fanhuijixutianjiaxinwen


Connect_mysql.php
 


In addition, if I want to implement the image upload function, please provide ideas. if someone has an example, it would be better. thank you!


Reply to discussion (solution)

Include ("connect_mysql.php ");
Mysql_open ();

Include ("connect_mysql.php ");
Mysql_open ();
No. click submit to open insert. php without executing the insert operation...

What does insert. php mean?

The landlord confirmed that the php environment is correct ???

Didn't you see the onclick event in the submit button of the landlord?

After reading the code of so many people, it is lz's best understanding !!!!

What does insert. php mean?
The default php file editor is used to open insert. php. for example, Emeditor is used to open insert. php by default ......

If the php environment is ready, is the file stored in the root directory of the web server? how can I access it?

If the php environment is ready, is the file stored in the root directory of the web server? how can I access it?
Php environment configuration should be fine. I use eclipse_php and put the file in D: \ Program Files \ Apache Software Foundation \ Apache2.2 \ htdocs \ TestInsert (TestInsert is the project name ), access http: // localhost/TestInsert/Page.html and enter the data. Then, click submit to bring up an http: // localhost/TestInsert/insert. php page, but nothing changes in the database.


What does insert. php mean?
The default php file editor is used to open insert. php. for example, Emeditor is used to open insert. php by default ......
This is wrong. ignore it. it should be an http: // localhost/TestInsert/insert. php page that is opened by IE.

The download page is displayed, indicating that the php environment is not matched successfully.

The download page is displayed, indicating that the php environment is not matched successfully.
I think it should not be an environment problem. if I write the insert statement directly in a php file (the value can be written directly), the data can be inserted into the database, however, this method cannot be obtained from the page.

The download page is displayed, indicating that the php environment is not matched successfully.
I have checked the installation of PHP5, Mysql, Apache, and eclipse, and I have not seen any problems...

, The problem occurs on the connected database,
If there is a problem with linking database functions, you can directly execute the function part that has been commented out below!
// Function mysql_open ()
//{
$ Mysql_servername = "localhost ";//
$ Mysql_username = "root ";
$ Mysql_password = "11111 ";
$ Mysql_dbname = "new ";

$ Conn = mysql_connect ($ mysql_servername, $ mysql_username, $ mysql_password );
Mysql_query ("set names UTF8"); // UTF8
Mysql_select_db ($ mysql_dbname, $ conn );
// Return $ conn;
//}

, The problem occurs on the connected database,
If there is a problem with linking database functions, you can directly execute the function part that has been commented out below!
// Function mysql_open ()
//{
$ Mysql_servername = "localhost ";//
$ Mysql_username = "root ";
$ Mysql_password = "11111 ";
$ Mysql_dbname = "new ";

$ Conn = mysql_connect ($ mysql_servername, $ mysql_username, $ mysql_password );
Mysql_query ("set names UTF8"); // UTF8
Mysql_select_db ($ mysql_dbname, $ conn );
// Return $ conn;
//}
This method is the same as that on the first floor.

 0) echo "xinwentianjiachenggong! ";?>
 Fanhuijixutianjiaxinwen


I changed the code to the above format and found through the error message that the insertion failed because the Id field is not filled, and there is still a problem in the above comments. I hope you can help me more. if you feel that the score is not enough, I can append it. I just think it is troublesome to open a post.

$ Result = mysql_query ($ sql1 );
The result obtained in this way is not a value such as 1, 2, and 3 stored in the database, and then the update fails. the Error: Incorrect integer value: ''For column 'id' at row 1. how can I obtain the correct id or result value through the query and insert the result to the database.

If id is the primary key, it is obviously incorrect to assign max (id) to it because the primary key cannot be repeated! Max (id) + 1
If id is a primary key and auto-increment, you do not need to assign a value to id.
If the id is not a primary key but cannot be blank, it is wrong to assign a value to the id.

In fact, as long as the result of mysql_error () is printed, everything is clear.

$ Id = mysql I _fetch_assoc ($ result); // Connect to mysql. here mysqli is used. it must be wrong and an array is returned.
At least.

$ SQL = "INSERT INTO new (id, title, content, time, news_cate_id)
VALUES
('". $ Id ['Max (id) ']. "','". $ _ POST ["title"]. "','". $ _ POST ["content"]. "', now (),". $ _ POST ["c_id"]. ")";

If your id is a primary key, an error occurs when you insert the same id.

If id is the primary key, it is obviously incorrect to assign max (id) to it because the primary key cannot be repeated! Max (id) + 1
If id is a primary key and auto-increment, you do not need to assign a value to id.
If the id is not a primary key but cannot be blank, it is wrong to assign a value to the id.

In fact, as long as the result of mysql_error () is printed, everything is clear.
If id is the primary key, it is obviously incorrect to assign max (id) to it because the primary key cannot be repeated! I know it should be max (id) + 1, but I wrote $ id ++ above, which is missing.
Id is the primary key. how do I set primary key auto-increment. Is it possible to set a table during table creation?

My Database SQL is as follows. what's wrong?

/*Navicat MySQL Data TransferSource Server         : testSource Server Version : 50153Source Host           : localhost:3306Source Database       : newTarget Server Type    : MYSQLTarget Server Version : 50153File Encoding         : 65001Date: 2013-06-04 14:21:53*/SET FOREIGN_KEY_CHECKS=0;-- ------------------------------ Table structure for `new`-- ----------------------------DROP TABLE IF EXISTS `new`;CREATE TABLE `new` (  `id` int(11) NOT NULL,  `title` varchar(50) DEFAULT NULL,  `content` varchar(100) DEFAULT NULL,  `time` datetime DEFAULT NULL,  `news_cate_id` int(11) DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ------------------------------ Records of new-- ----------------------------INSERT INTO `new` VALUES ('1', '111', '111', '2013-06-04 09:40:29', '1');INSERT INTO `new` VALUES ('2', 'eee', 'eeee', '2013-06-04 13:28:20', '1');

'Id' int (11) unsigned not null AUTO_INCREMENT,
In this case, the primary key is automatically increased, right?
$ SQL = "INSERT INTO new (id, title, content, time, news_cate_id)
VALUES
('". $ Id. "','". $ _ POST ["title"]. "','". $ _ POST ["content"]. "', now (),". $ _ POST ["c_id"]. ")";
How should I modify this part?

$ SQL = "INSERT INTO new (title, content, time, news_cate_id)
VALUES
('". $ _ POST ["title"]. "','". $ _ POST ["content"]. "', now (),". $ _ POST ["c_id"]. ")";

Now you know, you just need to change it to the original one. thank you for finishing the post. before you end the post, add a score to express your gratitude.

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.