What is the use of $_REQUEST variable in php?

0 votes
What is the use of  $_REQUEST variable in submitting the form?

thank you!
Mar 27 in PHP by kartik
• 10,760 points
49 views

1 answer to this question.

0 votes

Hii @kartik,

The $_REQUEST variable is used to read the data from the submitted HTML form.

Sample code:

Here, the $_REQUEST variable is used to read the submitted form field with the name ‘username’. If the form is submitted without any value, then it will print as “Name is empty”, otherwise it will print the submitted value.

<?php

if (isset($_POST['submit'])) {

// collect value of input field

$name = $_REQUEST['username'];

if (empty($name)) {

echo "Name is empty";

} else {

echo $name;

}

}

else

{

?>

<form method="post" action="#">

Name: <input type="text" name="username">

<input type="submit" name="submit">

</form>

<?php } ?>

Hope this is helpful

Thank you!

answered Mar 27 by Niroj
• 21,680 points

Related Questions In PHP

0 votes
1 answer

How can I handle the warning of file_get_contents() function in PHP?

Hello @kartik, This is fairly simple: if (!$data = ...READ MORE

answered Apr 7 in PHP by Niroj
• 21,680 points
39 views
0 votes
0 answers

What are the differences in die() and exit() in PHP?

I think both have the same functionality, ...READ MORE

Apr 8 in PHP by kartik
• 10,760 points
23 views
0 votes
1 answer

What is the best way to allow plugins for a PHP application?

Hello @kartik, I've used, it's an attempt to ...READ MORE

answered Apr 15 in PHP by Niroj
• 21,680 points
14 views
0 votes
1 answer

What are the vulnerability related to PHP Form?

Hii, The $_SERVER["PHP_SELF"] variable can be used by ...READ MORE

answered Feb 13 in PHP by Niroj
• 21,680 points
65 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 21,680 points
394 views
0 votes
1 answer

What is type casting and type juggling in php?

Hey, The way by which PHP can assign ...READ MORE

answered Mar 27 in PHP by Niroj
• 21,680 points
46 views
0 votes
1 answer

How can we create a session in PHP?

Hello @kartik, session_start() function is used in PHP to ...READ MORE

answered Mar 27 in PHP by Niroj
• 21,680 points
32 views
0 votes
1 answer

How to clone a JavaScript object?

Hello, You can clone an object and remove ...READ MORE

answered Apr 2 in Java-Script by Niroj
• 21,680 points
15 views
0 votes
1 answer

What is the use of the @ symbol in PHP?

Hello @kartik, The @ symbol is the error control operator ("silence" or "shut-up" ...READ MORE

answered Apr 8 in PHP by Niroj
• 21,680 points
37 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27 in PHP by Niroj
• 21,680 points
36 views