Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Undefined Inex Error???

    Hi All, 1st Timer...

    I have created PHP page with Form as follows:
    <?
    $Fname = $_POST["Fname"];
    $Lname = $_POST["Lname"];
    ?>

    <form method="post" action="<?php echo $PHP_SELF;?>">
    First Name:<input type="text" name="Fname"><br />
    Last Name:<input type="text" name="Lname"><br />
    <input type="submit" value="submit" name="submit">
    </form>

    & This is the error I am getting:
    Notice: Undefined index: Fname in c:\testform.php on line 2
    Notice: Undefined index: Lname in c:\testform.php on line 3

    Actually its pretty straightforward, and yet I cant figure it out. Please help. Thanks.
    jjdave...

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The error is telling you that the $_POST data with the names you are looking for doesn't exist - usually this means that either the field names are wrong on the form or the form wasn't submitted yet - from your code snippet it looks like the latter was the case.

    It should be easy enough to get around the problem by checking the $_POST data with isset() first:
    PHP Code:
    <? 
    if(isset($_POST['Fname']) {
        
    $Fname $_POST["Fname"]; 
    }
    if(isset(
    $_POST['Lname']) {
        
    $Lname $_POST["Lname"]; 
    }
    ?> 

    <form method="post" action="<?php echo $PHP_SELF;?>"> 
    First Name:<input type="text" name="Fname"><br /> 
    Last Name:<input type="text" name="Lname"><br /> 
    <input type="submit" value="submit" name="submit"> 
    </form>

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank You for your reply: I am still having problem. Well here is my whole code: (Also, One more thing, How do you guys post your code, so it keeps its coding colors, such as red, blue, green and orange???)

    <?
    include 'library/config.php'; // Assign Parameters to Localhost, UserName, Password

    if (!isset($_POST['Submit'])) // if page is not submitted to itself echo the form
    {
    $part_no=$_POST['part_no'];
    $part_desc=$_POST['part_desc'];

    include 'library/opendb.php'; // Connect to Database using Localhost, UserName, Password

    $query="INSERT INTO xproject VALUES ('','$part_no','$part_desc')";

    mysql_query($query); // Run the Query to create Table & Fields

    include 'library/closedb.php'; // Disconnect from the Database
    ?>


    <FORM Action="<?php echo $_SERVER['PHP_SELF']?>" Method="POST">

    PART NO:<input type="text" name="part_no"><br>
    DESCRIPTION:<input type="text" name="part_desc"><br>
    <input type="submit" name="Submit" value="SUBMIT"><br>

    </FORM>

    <?
    }
    else
    {
    echo "Part No & Description ".$part_no." ".$part_desc.".<br />";
    }
    ?>

    ==============================================
    NOTE that this form does work, I am not sure why I am getting this error message:

    Notice: Undefined index: part_no in c:\x1-testrecordadd\.php on line 6
    Notice: Undefined index: part_desc in c:\x1-testrecordadd.php on line 7
    Last edited by jjdave; 07-19-2005 at 12:02 AM.

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Use the PHP VbCode.

    And here's your trouble maker:

    PHP Code:
    $part_no=$_POST['part_no'];
    $part_desc=$_POST['part_desc']; 
    You are assigning values that don't exist.

  • #5
    New Coder
    Join Date
    Jul 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I moved all the Variables & SQL codes into the ELSE clause and now it works fine. Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •