I'm now starting to study php and testing some basic codes. I do have a problem with this simple "GET" code I have this php files tutorial1.php with code <?php $fname = "Lebron"; $lname = "james"; $address = "Los Angeles"; $job = "Player"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form name="form1" action="GET" action="processed.php"> First Name: <input name="fname" type="text" value="<?php echo $fname; ?>" /><br /> Last Name: <input name="fname" type="text" value="<?php echo $lname; ?>" /><br /> Address: <input name="fname" type="text" value="<?php echo $address; ?>" /><br /> Job: <input name="fname" type="text" value="<?php echo $job; ?>" /><br /><br /> <input type="submit" name="Submit" value="Pass The Code" /> </form> </body> </html> Code (markup): Once I click the submit button it should be redirected to processed.php and pass all the values that I'm getting from tutorial1.php but the problem is it seemed like I do not redirected to processed.php. Here's the code of processed.php <?php if ($_SERVER['REQUEST_METHOD'] == 'GET') { } else { die("Die now Bitch"); } if(isset($_GET["Submit"])) { $fname = $_GET["fname"]; $lname = $_GET["lname"]; $address = $_GET["address"]; $job = $_GET["job"]; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form name="form1" method="GET"> First Name: <input name="fname" type="text" value="<?php echo $fname; ?>" /><br /> Last Name: <input name="fname" type="text" value="<?php echo $lname; ?>" /><br /> Address: <input name="fname" type="text" value="<?php echo $address; ?>" /><br /> Job: <input name="fname" type="text" value="<?php echo $job; ?>" /><br /><br /> </form> </body> </html> Code (markup): Anyone here who can explain what seemed to be the error or mistakes on my code? I know this is very basic for you guys Thanks in advance!
on line 20 of tutorial1.php action="GET" (action="" is the target file) you want method="GET" so replace line 20 with <form name="form1" action="processed.php" method="get"> PHP: and also all the input fields have the name="fname" so change the lines 23-26 with : First Name: <input name="fname" type="text" value="<?php echo $fname; ?>" /><br /> Last Name: <input name="lname" type="text" value="<?php echo $lname; ?>" /><br /> Address: <input name="address" type="text" value="<?php echo $address; ?>" /><br /> Job: <input name="job" type="text" value="<?php echo $job; ?>" /><br /><br /> PHP: that should do it!
The php site has a HUGE reference for coding with examples. Comes in very handy.. its a my first check before google for coding issues.