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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help me to fix undefined index on my php code

    1.<?php
    2.$db_connect = mysql_connect ('localhost', 'root', '');
    3.if (!$db_connect) {
    4. die ('cannot connect: ' . mysql_error());
    5. }
    6.
    7.$db_select = mysql_select_db ('trial', $db_connect);
    8.if (!$db_select) {
    9. die ('cant connect: ' . mysql_error());
    10. }
    11.
    12.$FirstName = $_POST['Fn'];
    13.$LastName = $_POST['Ln'];
    14.
    15.$sql = "INSERT INTO sample (FirstName, LastName) VALUES ('$FirstName', '$LastName')";
    16.if (!mysql_query($sql)) {
    17.die ('cant connect: ' . mysql_error());
    18.}
    19.
    20.mysql_close ();
    21..?>

    Notice: Undefined index: Fn in C:\wamp\www\trial\last.php on line 12
    Notice: Undefined index: Ln in C:\wamp\www\trial\last.php on line 13


    HELP ME TO FIX THE ERROR

  • #2
    Regular Coder
    Join Date
    Mar 2011
    Posts
    148
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Hi
    In the form that sends data to that php script you should have fields with: name="Fn", and name="Ln" .

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    40
    Thanks
    0
    Thanked 9 Times in 9 Posts
    or try:

    PHP Code:
    if(!empty($POST)) {
    $FirstName $_POST['Fn'];
    $LastName $_POST['Ln'];



  •  

    Posting Permissions

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