Problem with GET (PHP beginner)

Discussion in 'PHP' started by irule272, Mar 17, 2010.

  1. #1
    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!
     
    irule272, Mar 17, 2010 IP
  2. bozghiyy

    bozghiyy Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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!
     
    bozghiyy, Mar 17, 2010 IP
    irule272 likes this.
  3. irule272

    irule272 Well-Known Member

    Messages:
    1,153
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    155
    #3

    I missed that "method" on the form lol.

    Thanks you very much for this mate :)

    Problem solved!
     
    irule272, Mar 17, 2010 IP
  4. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    you should read php manual
     
    guardian999, Mar 18, 2010 IP
  5. JosephSEO

    JosephSEO Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    JosephSEO, Mar 18, 2010 IP
  6. clemsans20

    clemsans20 Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I missed doing PHP. It gave us headaches, but it's worth it..
     
    clemsans20, Mar 18, 2010 IP