Can GET be used, but POST cannot? -Php Tutorial

Source: Internet
Author: User
Can GET be used, but POST cannot? First run the code:
Html:




Add user







Adduser. php:

Require_once "connectDB. php ";
Print_r ($ _ POST );
// Var_dump ($ _ POST;
$ Fname = $ _ POST ['fname'];
$ Age = $ _ POST ['age'];

$ Conn = connectDB ();
Mysqli_query ($ conn, "insert into user (name, age) VALUES ('$ fname',' $ age ')");

?>

Output:
Array ()
Notice: Undefined index: fname in C: \ xampp \ htdocs \ DataBase \ adduser. php on line 21

Notice: Undefined index: age in C: \ xampp \ htdocs \ DataBase \ adduser. php on line 22

Check that there is an empty data insert in the database. However, after you replace post With get, you can insert the correct data.


Reply to discussion (solution)

There is no problem with the two files.

Post the real code!
The error lines are 21 and 22. you only gave a few lines to adduser. php.

Post the real code!
The error lines are 21 and 22. you only gave a few lines to adduser. php.



I didn't post the comments.
Real code:

 


Post the real code!
The error lines are 21 and 22. you only gave a few lines to adduser. php.



I didn't post the comments.
Real code:

/**
* Created by PhpStorm.
* User: 541464750
* Date: 2016/1/13
* Time: $0: 49
*/

// If (! Isset ($ _ GET ['fname'])
//{
// Die ("no name ");
//}
// If (! Isset ($ _ GET ['age'])
//{
// Die ("no age ");
//}
Require_once "connectDB. php ";
Print_r ($ _ GET );
// Var_dump ($ _ GET;
$ Fname = $ _ GET ['fname'];
$ Age = $ _ GET ['age'];

$ Conn = connectDB ();
Mysqli_query ($ conn, "insert into user (name, age) VALUES ('$ fname',' $ age ')");

// Header ("Location: alluser. php ");
?>



Here we just changed the POST to GET and the others are the same as before.

There is no problem with the two files.


In other places, too. can GET be used and POST be used? is it because of the system or setup?


There is no problem with the two files.


In other places, too. can GET be used and POST be used? is it because of the system or setup?


Your real code uses $ _ GET? Print a null value, which is normal ..
The code and errors you posted to the main building are not correct.
The more you paste the code, the less clearly you describe the problem ..



There is no problem with the two files.


In other places, too. can GET be used and POST be used? is it because of the system or setup?


Your real code uses $ _ GET? Print a null value, which is normal ..
The code and errors you posted to the main building are not correct.
The more you paste the code, the less clearly you describe the problem ..



It is enough to check my main building code. I just deleted some comments and sent them out.
When I use GET, the print output is not a null value, but POST is a null value.

Use the developer mode of the browser for debugging. First, check whether there is data Post in the request header.

Use the developer mode of the browser for debugging. First, check whether there is data Post in the request header.


I don't know how to read this, but I printed the null value in POST with print. do you mean to let me see whether the data is not passed or the data is not received.

It's strange. what about intercepting post?

The cause is found... It is because I started a webpage using phpstorm, instead of using apache, and changed it to the apache port to open the webpage.

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.