www.webdeveloper.com
Results 1 to 5 of 5

Thread: Notice: Undefined index: name in C:\xampp\htdocs

  1. #1
    Join Date
    Sep 2013
    Posts
    221

    Unhappy Notice: Undefined index: name in C:\xampp\htdocs

    Hello experts,
    I am running with an app and i have some notice error while inserting records.
    My form code is pasted below:
    HTML Code:
    <form action="add_bk_insert.php">
    
    Name <input type="text"  name="name"/><br />
    E-mail <input type="text"  name="email" /><br />
    Contact <input type="text"  name="contact" /><br />
    Requirement <input type="text"  name="requirement" /><br />
    
    <input type="submit" value="Submit" />
    
    </form>
    and my add_bk_insert.php code is as shown below:

    PHP Code:
    <?php

    mysql_connect
    ("localhost","root","");

    mysql_select_db("test");

    $order "INSERT INTO sal2

                (name,email_id, contact,requirement)

                VALUES

                ('
    $_POST[name]','$_POST[email_id]','$_POST[contact]','$_POST[requirement]')";

    $result mysql_query($order); 

    if(
    $result){

     echo 
    "Inserted";   
     
    //include_once("testimonials.php");
    } else{

        echo(
    "<br>Input data is fail");

    }

    ?>
    when i run the above code it shows a notice error as below:

    HTML Code:
    Notice: Undefined index: name 
    
    Notice: Undefined index: email_id 
    
    Notice: Undefined index: contact 
    
    Notice: Undefined index: requirement 
    So i dont know what exactly i am missing. Please some one can help me out with this.
    I am really stuck.
    strad solutionswww.stradsolutions.com

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    565
    Over 100 views and nobody wanted to give you this info.

    First - horrible coding. Once again - NEVER ACCEPT INPUT FROM THE CLIENT THAT IS NOT ESCAPED BEFORE YOU PUT IT INTO YOUR DATABASE. You are just BEGGING to be hacked.

    That said -

    Go look at your PHP reference manual/book/resource and read up on how to write an array reference. Or try to think like the PHP interpreter. If I'm the interpreter I'm looking at this:

    $_POST[email_id]

    and saying to myself:

    ok - this guy wants a value from my $_POST array. Got it. But what is this email_id thingy? I don't know any PHP variable by that name. What to do with this thing? ok - I'll put out a warning message saying "I don't know what this index you've given me is". Which is exactly what PHP has done.

    Now go educate yourself with a little reading.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Well, the root cause of your specific problem is not having method="post" in your form tag. Even after fixing that, you should still use isset() or empty() to verify the $_POST values you need are actually there before you try to use them.

    As alluded to above, though, there are issues with using unsanitized inputs directly in your SQL. At the very least, look into mysql_real_escape_string(). Better yet would be to use PDO or MySQLi extensions and make use of prepared statements with bound parameters.

    http://xkcd.com/327/
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Apr 2012
    Posts
    38
    the error you get is saying there is no value assigned to that variable. As said above.
    If you encounter this error later on you might want to consider putting an @ in front of your $_POST['variable name'].
    Doing this will prevent it from giving an error like this. (in the current situation you should really prevent your script from inserting empty rows)

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Quote Originally Posted by GettingSmart View Post
    the error you get is saying there is no value assigned to that variable. As said above.
    If you encounter this error later on you might want to consider putting an @ in front of your $_POST['variable name'].
    Doing this will prevent it from giving an error like this. (in the current situation you should really prevent your script from inserting empty rows)
    I'm not a fan of using the "@" error suppression operator, as that's just sweeping your garbage under the rug instead of really getting rid of it (the garbage, not the rug). I prefer to develop with all error/warning/info messages enabled; then code, test, add defensive code, test some more, etc., until there are no errors/warnings.

    With experience you learn the common places where such things happen, and start putting in that defensive coding from the beginning.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles