CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2010
    Posts
    161

    Undefined Index name

    Hello everyone

    I'm learning PHP because I want to develop some websites and have I set up web development environment.

    I am using XAMPP + YII + Eclipse PHP IDE

    Everything works perfectly but I was following a guide and eventhough I followed step by step, I'm getting an error that isn't supposed to be there.

    Code:
    <!DOCTYPE HTML>
    
    <html>
    
    
    <link rel="stylesheet" type="text/css" href="css/main.css">
    
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Contact Form</title>
    </head>
    
    <body>
    
        <header class="body">
        </header>
    
        <section class="body">
    <?php
        $name = $_POST['name'];   <!-- This is where I get the error undefined index name?>
        $email = $_POST['email'];
        $message = $_POST['message'];
        $from = 'From: DEMO'; 
        $to = '[email protected]'; 
        $subject = 'Hello';
    ?>
      <form method="post" action="index.php">
            
        <label>Name</label>
        <input name="name" placeholder="Type Here">
                
        <label>Email</label>
        <input name="email" type="email" placeholder="Type Here">
                
        <label>Message</label>
        <textarea name="message" placeholder="Type Here"></textarea>
                
        <input id="submit" name="submit" type="submit" value="Submit">
            
    </form>
    
        </section>
     
        
    
        <footer class="body">
        </footer>
    
    </body>
    
    </html>
    I am getting the error in the php script that I've embedded inside the index.php file, so yeah the html and php code are in the same index.php file , that's why the form is pointing to the same file.

    Any help will be appreciated. Thank you

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Undefined Index name

    Unless the page is being loaded from the form actually being posted, then there is no post data. So, to keep the actual form processing code from loading when the page isn't posting data, you simple make sure the variables are being set.

    PHP Code:
    <?php
    if (isset($_POST['name'])) {
        
    $name $_POST['name'];
        
    $email $_POST['email'];
        
    $message $_POST['message'];
        
    $from 'From: DEMO'
        
    $to '[email protected]'
        
    $subject 'Hello';
    }
    ?>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jan 2010
    Posts
    161

    Re: Undefined Index name

    Thank you for the reply, so basically the isset function checks wether the box name is filled or not right?

    I want to try to send an email to me but I'm doing this work offline, what I mean is that I'm using offline server to test my website (on XAMPP) - can I send email offline or I must upload my code on an online server?

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Undefined Index name

    isset() simply detects if a variable has been created or not.

    To send mail, your PHP configuration must have access to a mail server. If you don't...you cannot send mail.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jan 2010
    Posts
    161

    Re: Undefined Index name

    so is it there anyway to have access to the mail server when developing in localhost ?

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Undefined Index name

    Download a copy of Mercury Mail Server and then make sure your PHP configuration file is setup for SMTP output.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Jan 2010
    Posts
    161

    Re: Undefined Index name

    Thank you

    I will try this.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured