Guide for filling in records with the same field into multiple tables

Source: Internet
Author: User
Why is this incorrect?

$ Username = $ _ POST ['username'];
$ Password = $ _ POST ['psd '];
$ Sex = $ _ POST ['Sex '];
$ Grade = $ _ POST ['Grad'];
$ Age = $ _ POST ['age'];
$ Height = $ _ POST ['height'];
$ Weight = $ _ POST ['weight'];

// Check form data
If (! Preg_match ('/^ [\ w \ x80-\ xff] {3, 15} $/', $ username )){
Exit ('error: the user name does not meet the requirements! Back ');
}
If (strlen ($ password) <6 ){
Exit ('error: Invalid password length! Back ');
}


Include ('Conn. php ');


$ SQL = "INSERT INTO user (username, password, sex, grade, age, height, weight) VALUES ('$ username',' $ password', '$ sex ', '$ grade', '$ age',' $ height', '$ weight ')";
Insert into module1 (username) VALUES ('$ username ');
Insert into module2 (username) VALUES ('$ username ');
Insert into module3 (username) VALUES ('$ username ');
Insert into module4 (username) VALUES ('$ username ');
Insert into module5 (username) VALUES ('$ username ');
If (mysql_query ($ SQL, $ conn ))
Exit ('registration successful! Click here to log on ');
Else
Echo 'Sorry, registration error! : ', Mysql_error (),'
';
Echo 'click here to return retry ';

?>


Reply to discussion (solution)

Is the test successful? What error is reported if the task fails?

Assignments that must be handed in before this evening,

Add session_start () to the beginning of reg. php ();

Session start has already written the username definition variable on the login page. can this be done?

Do I use two session variables on the registration and login pages?
It is defined in reg. php and then logged out. Is that true?

Do I use two session variables on the registration and login pages?
It is defined in reg. php and then logged out. Is that true?

Sorry, that session_start was not your mistake. I answered others' posts and accidentally replied to you.
Echo 'Sorry, registration error! : '. Mysql_error ().'
'; Your error line 24 should contain commas to periods

It should not be caused by this error. Because I insert the 2-5 insert into statement (), that is, only one insert statement is normal.

Oh, I noticed you.
$ SQL. = 'Insert INTO module1 (username) VALUES ('$ username ');'
$ SQL. = 'Insert INTO module2 (username) VALUES ('$ username ');'
$ SQL. = 'Insert INTO module3 (username) VALUES ('$ username ');'
$ SQL. = 'Insert INTO module4 (username) VALUES ('$ username ');'
$ SQL. = 'Insert INTO module5 (username) VALUES ('$ username ');'
Then, mysqli: multi_query () is used to support multi-statement execution. mysql can only be executed in a single statement. Therefore, you can insert five times to execute mysql_query five times.

It should not be caused by this error. Because I insert the 2-5 insert into statement (), that is, only one insert statement is normal.

Thank you. let me give it a try.

I won't change it. everything is wrong... Is where the if statement

You still need to go to the manual and use mysqli. you also need php to support mysqli extension.

If not, write mysql_query five times.


$ Username = $ _ POST ['username'];
$ Password = $ _ POST ['psd '];
$ Sex = $ _ POST ['Sex '];
$ Grade = $ _ POST ['Grad'];
$ Age = $ _ POST ['age'];
$ Height = $ _ POST ['height'];
$ Weight = $ _ POST ['weight'];

// Check form data
If (! Preg_match ('/^ [\ w \ x80-\ xff] {3, 15} $/', $ username )){
Exit ('error: the user name does not meet the requirements! Back ');
}
If (strlen ($ password) <6 ){
Exit ('error: Invalid password length! Back ');
}


Include ('Conn. php ');


$ SQL = "INSERT INTO user (username, password, sex, grade, age, height, weight) VALUES ('$ username',' $ password', '$ sex ', '$ grade', '$ age',' $ height', '$ weight ')";
$ Sql1 = insert into module1 (username) VALUES ('$ username ');
$ Sql2 = insert into module2 (username) VALUES ('$ username ');
$ Sql3 = insert into module3 (username) VALUES ('$ username ');
$ Sql4 = insert into module4 (username) VALUES ('$ username ');
$ Sql5 = insert into module5 (username) VALUES ('$ username ');
$ Sql6 = insert into module5 (username) VALUES ('$ username ');
$ Result = mysql_query ($ SQL, $ conn );
$ Result1 = mysql_query ($ sql1, $ conn );
$ Result2 = mysql_query ($ sql2, $ conn );
$ Result3 = mysql_query ($ sql3, $ conn );
$ Result4 = mysql_query ($ sql4, $ conn );
$ Result5 = mysql_query ($ sql5, $ conn );
$ Result6 = mysql_query ($ sql6, $ conn );
If ($ result & $ result2 & $ result3 & $ result4 & $ result5 & $ result6)
Exit ('registration successful! Click here to log on ');
Else
Echo 'Sorry, registration error! : ', Mysql_error (),'
';
Echo 'click here to return retry ';

?>

$ Sql1 = "insert into module1 (username) VALUES ('$ username')"; note that if there is no bank semicolon, this is also an error. I don't want to talk about these details.

You have a lot of details in this code. (The English brackets are connector numbers, not Comma. these are the most basic.

No. After debugging, it may have been converted to paste.

Anyway, thank you very much.

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.