Simple PHP: Getting Variable From A Form Input October 05, 2022 Post a Comment I can't really use PHP and from what I've seen in tutorials this should work, but it doesn't: Solution 1: PHP is a server-side language, so you'll need to submit the form in order to access its variables. Since you didn't specify a method, GET is assumed, so you'll need the $_GET super-global: echo $_GET['name']; Copy It's probably better though, to use $_POST (since it'll avoid the values being passed in the URL directly. As such, you can add method attribute to your <form> element as follows: <form method="post"> <input type='text' name="name" value="myName" /> <input type="submit" name="go" value="Submit" /> </form> Copy Notice I also added a submit button for good measure, but this isn't required. Simply hitting return inside the textbox would submit the form. Solution 2: Well, you have to POST your form to get the value of $_POST variables. Add this to your <form>Baca JugaJavascript Code For Input Range Slider Not Working In Internet Explorer 11Keep Data In Html Form After Form SubmittedMy Captcha Image Not Showing On My Page When The Captcha.php Is Called <form action="yourpagename.php" method="post"> <input type='text' name="name" value='myName'> <button type="submit">Submit</button> </form> Copy Click button and whatever is typed in your field will show up. Solution 3: <html> <body> <form method="post" action="1.php"> Name: <input type="text" name="fname"> <input type="submit"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // collect value of input field $name = $_POST['fname']; if (empty($name)) { echo "Name is empty"; } else { echo $name; } } ?> </body> </html> Copy Solution 4: try this <?php if(isset($_REQUEST['name'])){ $name = $_REQUEST['name']; echo $name; } ?> Copy Share You may like these postsPhp - Email Not Sending As Html. Why?Send Multiple Button Information Through FormIts Outputs Details Incorrectly In Php/htmlHow To Filter By Hiding/showing Divs With Dynamic Attributes? Post a Comment for "Simple PHP: Getting Variable From A Form Input"
Post a Comment for "Simple PHP: Getting Variable From A Form Input"