undefined index

Discussion in 'PHP' started by kharearch, Jun 29, 2009.

  1. #1
    It gives following error -

    Array ( [name] => asha => ffffff [address] => ttttt [Submit] => Submit )
    Notice: Use of undefined constant name1 - assumed 'name1' in C:\wamp\www\dreamweaver site\add.php on line 10

    Notice: Undefined index: name1 in C:\wamp\www\dreamweaver site\add.php on line 10

    Notice: Undefined index: email1 in C:\wamp\www\dreamweaver site\add.php on line 11

    Notice: Undefined index: address1 in C:\wamp\www\dreamweaver site\add.php on line 12



    my program code is -


    [B]contact.php[/B]



    <body>
    <form name='form1' method="post" action="add.php">
    <table width="942" height="335" border="1">
    <tr>
    <td><label></label>
    &nbsp;Name</td>
    <td><label>
    <input type="text" name="name" />
    </label></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Email</td>
    <td><label>
    <input type="text" name="email" />
    </label></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Address</td>
    <td><label>
    <textarea name="address"></textarea>
    </label></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td><label>
    <input type="submit" name="Submit" value="Submit" />
    <br />
    <br />
    </label></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr> <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>

    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
    <form>
    </body>



    [B]add.php[/B]


    <body>
    <?php
    print_r($_POST);
    $n=$_REQUEST[name1];
    $e=$_REQUEST['email1'];
    $a=$_POST['address1'];
    echo $n;
    echo $e;
    echo $a;
    ?>
    </body>



    please help me to solve this problem.
     
    kharearch, Jun 29, 2009 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    arrays start from 0 not one i guess

    Also in your forms why you use name1, email1, address1 when your form doesnt have 1 as the name
     
    Bohra, Jun 29, 2009 IP
  3. kharearch

    kharearch Member

    Messages:
    82
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    sorry. It is duplicate program. in my orignal contact.php program I have given control name as name1, email1 and address1. Thanks.
     
    kharearch, Jun 29, 2009 IP
  4. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #4
    In add.php change the name1 line to this:

    
    $n=$_REQUEST['name1'];
    
    PHP:
    You get the undefined index, because you are trying to call up an element with as a constant (i.e. define('constant_name', 'constant_value')). Basically, if you want to access an element - put it in quotes.
     
    Louis11, Jun 29, 2009 IP