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 Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validation problem

    I have two pages. One is registration, and the other is validation to validate the input.

    Register.php is as like this:
    <form name="signup" action="validate.php" method="post">
    <table width="751">
    <tr>
    <td width="78"><b>First Name</b></td>
    <td width="185"><input type="text" name="fname" size="20" ></td>

    <td width="79"><b>Last Name</b></td>
    <td width="185"><input type="text" name="lname" size="20" ></td>
    </tr>
    </table>
    <input type="submit" value="Continue>">
    </form>

    validate.php is as follows

    <?php

    //require("db.php");
    $message="<b><font size=\"4\">Please enter your:</font></b> ";
    $message= $message. "<font size=\"3\" color=\"#FF0000\">";
    $returnValue = true;

    //First name
    if ($fname == "" || $fname == '')
    {
    $message = $message ."<b><br>First name";
    $returnValue = false;
    }
    //Last name
    if ($lname == "")
    {
    $message= $message . "<br>Last name ";
    $returnValue = false;
    }
    if($returnValue)
    {
    session_start();

    $_SESSION['fname'] = $fname ;
    $_SESSION['lname'] = $lname ;
    }
    else
    {
    print("<html><head><link rel=\"stylesheet\" href=\"mystyles.css\" type=\"text/css\"><title>Data Validation</title></head>
    <body class=\"validation\">");
    print($message. "</font>");
    print("<br><br><font size=\"3\" color=\"#0000FF\">Press the back button.</font></b>");
    print("</body></html>");
    }

    It used to work before but stopped at some point. So even if I type the first name and last name it doesn't see it. Does anybody know why? Thank you.

  • #2
    New Coder
    Join Date
    Sep 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Register Globals is most likely Off, which is good thing. Anyways to access your input variables, you need to use the SUPER GLOBAL that holds the input variables name value pairs -> name=value.

    So your form, is using the method post, so your input variables if they are set, will be found in the SUPER_GLOBAL -> $_POST...

    PHP Code:
    $_POST['fname'];
    $_POST['lname']; 

    You script might look like this...

    PHP Code:
    <?php

    // don't use (), require is a language construct, not a function!

    require 'db.php';

    $message $f_test $l_test '';

    if ( isset ( 
    $_POST['fname'] ) )
    {
        
    $f_test trim $_POST['fname'] );

        if ( empty ( 
    $f_test ) )
        {
            
    $message .= '<br />First Name';
        }
    }

    if ( isset ( 
    $_POST['lname'] ) )
    {
        
    $l_test trim $_POST['lname'] );

        if ( empty ( 
    $l_test ) )
        {
            
    $message .= '<br />Last Name';
        }
    }

    if ( empty ( 
    $message ) )
    {
        
    session_start();

        
    $_SESSION['fname'] = $f_test;
        
    $_SESSION['lname'] = $l_test;
    }
    else
    {
    ?>
    <html>
        <head>
            <link rel="stylesheet" href="mystyles.css" type="text/css">
            <title>Data Validation</title>
        </head>
        <body class="validation">
            <font size="4">
                <b>
                    Please enter your:
                </b>
            </font>
            <font size="3" color="#FF0000">
                <b>
    <?php echo $message?>
                </b>
            </font>
            <br />
            <br />
            <font size="3" color="#0000FF">
                <b>
                    Press the back button.
                </b>
            </font>
        </body>
    </html>
    <?php
    }
    ?>

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you.


  •  

    Posting Permissions

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