User input in PHP. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

User input in PHP.

I have just started learning php.I am confused about taking some input from user like we do in python or java.

2nd Jun 2018, 3:38 PM
Mitali
Mitali - avatar
6 Answers
+ 18
PHP is a little weird in the sense that it relies on HTML to gather all of its information and data, meaning that you can't take user input directly in from your PHP code. The way that you do so is by implementing a form within your HTML code and linking it to your PHP file (because of this, you can't really take user input with PHP on Sololearn). Hope this helped! d:
2nd Jun 2018, 3:44 PM
Faisal
Faisal - avatar
+ 10
Actually, You CAN use the command line to have input from. It is like any other language, You have STDIN. If You want to read data sent via the network, The best option is to use POSTMAN or create a simple page which will utilize methods such as (ofc) GET, POST, PUT and handle them. To create a handle for STDIN use: "fopen ("php://stdin","r");"
2nd Jun 2018, 8:39 PM
Jakub Dubański
Jakub Dubański - avatar
+ 6
Faisal Thanks.
2nd Jun 2018, 3:46 PM
Mitali
Mitali - avatar
+ 4
You can also use ajax (a javascript method which can send information to a specific url without reloading the page). That can be really helpful.
2nd Jun 2018, 4:52 PM
Αητοιπe
Αητοιπe - avatar
+ 2
Spaarwiel Yeah, PHP works better (for what I know) when separated by a file
4th Jun 2018, 12:03 PM
Faisal
Faisal - avatar
0
Faisal so you can have all your php in different files? https://www.sololearn.com/discuss/1325020/?ref=app
4th Jun 2018, 6:51 AM
J. Le Roux
J. Le Roux - avatar