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
    Feb 2012
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post Undefined index: Submit in localhost on line 19

    Hello,
    I have a forum I am creating, when load it in my browser, the forum loads and displays correctly, however, I get an error statingnotice: Undefined index: Submit in C:\xampp\folder\file.php on line 19 Can someone explain what is causing the error, here is my code.

    PHP Code:
    <?php
    session_start
    ();

    include (
    'dbc.php');
     
    //Form Error Checking.
    if ($_POST['Submit'] == 'Submit')
    //if (!isset($_POST['Submit']) || ($_POST['Submit'] != 'Submit'))
    {
        
    //Verify Service Order# is Eight Charecters.
        
    if (strlen($_POST['servord_num']) < 8)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "ERROR: Invalid Service Order #..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
    //Verify Customer Reference # is 11 Charectors
        
    if (strlen($_POST['custref_num']) < 11)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "ERROR: Invalid Customer Reference #..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
    //Verify Technicians Name
        
    if (strlen($_POST['tech_name']) < 5)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "ERROR: Please Enter Your First & Last Name..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
    //Verify Technicians Phone
        
    if (strlen($_POST['tech_phone']) < 10)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "ERROR: Please Enter Your Contact Phone..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
    //Verify Technicians E-Mail
        
    if (strlen($_POST['tech_email']) < 5)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "Incorrect email format, Please enter valid email address..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
    //Dispatching Company
        
    if (strlen($_POST['reportto_comp']) < 5)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "Enter Company Dispatched From..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
    //Servicing Company
        
    if (strlen($_POST['serv_comp']) < 3)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "Enter Name Of Company Where Equipment Is Being Serviced..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
    //Client's Address
        
    if (strlen($_POST['client_addr']) < 10)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "Address Of Company Where Equipment Is Being Serviced..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
    //Clien's Phone
        /*if (strlen($_POST['client_phone']) < 10)
           {
            echo("<br><br><br><br><br><br>");    
            die ("Enter Clients Ten or Eleven Digit Phone Number..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        }*/
        //Service Date
        
    if (strlen($_POST['serv_month']) < && ($_POST['serv_day']) < && ($_POST['serv_year']) < 4)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "Incorrect Date Format, Enter Correct Date In The Proper Format \"mm/dd/yyyy\"..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
    //Arrival Time At Clients Location.
        
    if (strlen($_POST['arv_time']) < 5)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "Enter The Time You Arrived At Clients Site..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
    //Departure Time From Clients Location.
        
    if (strlen($_POST['dep_time']) < 5)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "Enter Time You Departed From Clients Site..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
    //Milage OneWay.
        
    if (strlen($_POST['miles_oneway']) < 1)
           {
            echo(
    "<br><br><br><br><br><br>");    
            die (
    "Enter The Miles Traveled Oneway To Clients Location..<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>");?>
            <p></p>
    <p>&nbsp;</p>
            </div>
            <div id="content_bottom"></div>
          </div>
       </div><?php
        
    }
        
        
        
    //Query To Insert Date Into MySQL Database.
        
    $insert mysql_query("INSERT INTO invoice
                      (`servord_num`,`custref_num`,`tech_name`,`tech_phone`,`tech_email`,`reportto_comp`,`serv_comp`,`client_addr`,`client_phone`,`serv_month`,`serv_day`,`serv_year`,`arv_time`,`dep_time`,`miles_oneway`,`parking`,`toll`)
                      VALUES
                      ('$_POST[servord_num]','$_POST[custref_num]','$_POST[tech_name]','$_POST[tech_phone]','$_POST[tech_email]','$_POST[reportto_comp]','$_POST[serv_comp]','$_POST[client_addr]','$_POST[client_phone]','$_POST[serv_month]','$_POST[serv_day]','$_POST[serv_year]','$_POST[arv_time]','$_POST[dep_time]','$_POST[miles_oneway]','$_POST[parking]','$_POST[toll]')"
    ) or die(mysql_error());
        
        
    $message 
    "Thank you for registering with Fantasy Nails & Spa.\nYour login details are displayed below, please save this information in a safe place...\n\n
    User Email: $_POST[tech_email] \n\n\n
    You may login by clicking the link below or copying and pasting the url into your browser:\n
    http://norcopathfinders.com/mergedfantasy/login.php or 

    _____________________________________________
    Thank you. This is an automated response. PLEASE DO NOT REPLY.
    "
    ;
        
        echo(
    "Time Loged Successfully! Select the \"History\" link to see a list of the times inputed into the database....<br>Please check your e-mail address for a link to log into your account.");
        echo(
    "<br><br><br><br><br><br><br><br><br><br>");
        
    ?><p></p>
    <p>&nbsp;</p>
            </div>
        <div id="content_bottom"></div><?php
        
        
    exit;
        }
    ?> 
    <link href="styles.css" rel="stylesheet" type="text/css">
    <?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } 

    // Populate Password Fields With Random Password.


    /** 
     * The letter l (lowercase L) and the number 1 
     * have been removed, as they can be mistaken 
     * for each other. 
     */ 

    function createRandomPassword() { 

        
    $chars "abcdefghijkmnopqrstuvwxyz023456789"
        
    srand((double)microtime()*1000000); 
        
    $i 0
        
    $pass '' 

        while (
    $i <= 7) { 
            
    $num rand() % 33
            
    $tmp substr($chars$num1); 
            
    $pass $pass $tmp
            
    $i++; 
        } 

        return 
    $pass



    // Usage 
    $password createRandomPassword(); 
    //echo "Your random password is: $password"; 
    //echo "You are not authorized to view the contents of this page. Contact your site administrator.";




    ?>
    Forum:
    Code:
    <tr>
            <td></td>
            <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
            <td></td>
        </tr> 
        </form>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,593
    Thanks
    0
    Thanked 645 Times in 635 Posts
    I think the line causing that error is:

    Code:
    if (strlen($_POST['custref_num']) < 11)
    if $_POST['custref_num'] doesn't exist then the value being passed to strlen() is invalid.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Line 19 in my code is
    PHP Code:
    if ($_POST['Submit'] == 'Submit'
    I believe that the submit button may not be validating, however, when I fill in the form, and select submit, It does enter the fields in mysql backend database in the proper fields. I'm not sure why I get this error when seems to be passing data correctly?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Not sure why this is in the mysql forum; moving to PHP.
    None of these lines match up. But the error has to be right here since its the only use of an offset called 'Submit':
    PHP Code:
    //Form Error Checking.
    if ($_POST['Submit'] == 'Submit'
    That should be:
    PHP Code:
    if (isset($_POST['Submit']) && $_POST['Submit'] == 'Submit'
    Although due to IE you shouldn't check on this field as it will not obey sending its successful submit button unless its actually clicked. Use an isset check on each field that is expected instead: isset($_POST['servord_num'], $_POST['custref_num'], ....). You'll also want to look into SQL injections and how to secure your code.

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,283
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Quote Originally Posted by captainer View Post
    I get an error statingnotice: Undefined index: Submit in C:\xampp\folder\file.php on line 19
    Quote Originally Posted by felgall View Post
    I think the line causing that error is:

    Code:
    if (strlen($_POST['custref_num']) < 11)
    if $_POST['custref_num'] doesn't exist then the value being passed to strlen() is invalid.
    felgall, do you actually try to understand these things before posting? - This isn't the first or second time I've noticed your posts pinning down the wrong issue.

    As Fou says, (more 3explicit information is in my signature) IE does not send the submit button value if you don't click it with the mouse pointer. That means if you have a cursor in the text box and hit the return key then $_POST['Sumit'] will not exist causing an undefined index error.

    @captainer for more information click the link that relates to this in my signature. There is also a video demonstration of the IE quirk in action.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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