Results 1 to 3 of 3

Thread: Help with login register script ( again )

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default Help with login register script ( again )

    PHP Code:
    <html>

    <head>
    <script>



    var checkobj

    function agreesubmit(el){
    checkobj=el
    if (document.all||document.getElementById){
    for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
    var tempobj=checkobj.form.elements[i]
    if(tempobj.type.toLowerCase()=="submit")
    tempobj.disabled=!checkobj.checked
    }
    }
    }

    function defaultagree(el){
    if (!document.all&&!document.getElementById){
    if (window.checkobj&&checkobj.checked)
    return true
    else{
    alert("Please read/accept terms to submit form")
    return false
    }
    }
    }

    </script>

    <script language="javascript">

    function disableField()
    {
    document.getElementById('checky').disabled = false;
    }
    </script>


    </head>

    <body>
    <body style="background-color:lightgreen">
    <?php
    require "database.php";


     
    //This code runs if the form has been submitted
     
    if (isset($_POST['submit'])) { 

     
    //This makes sure they did not leave any fields blank
     
    if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['firstname'] | !$_POST['lastname'] |  !$_POST['age'] |  !$_POST['gender'] |  !$_POST['email'] | !$type ) {
             die(
    'You did not complete all of the required fields');
         }

     
    // checks if the username is in use
         
    if (!get_magic_quotes_gpc()) {
             
    $_POST['username'] = addslashes($_POST['username']);
         }
     
    $usercheck $_POST['username'];
     
    $check mysql_query("SELECT username FROM users WHERE username = '$usercheck'"
    or die(
    mysql_error());
     
    $check2 mysql_num_rows($check);

     
    //if the name exists it gives an error
     
    if ($check2 != 0) {
             die(
    'Sorry, the username '.$_POST['username'].' is already in use.');
                     }

     
    // this makes sure both passwords entered match
         
    if ($_POST['pass'] != $_POST['pass2']) {
             die(
    'Your passwords did not match. ');
         }

         
    // here we encrypt the password and add slashes if needed
         
    $_POST['pass'] = md5($_POST['pass']);
         if (!
    get_magic_quotes_gpc()) {
             
    $_POST['pass'] = addslashes($_POST['pass']);
             
    $_POST['username'] = addslashes($_POST['username']);
                 }
    if(
    $_POST[firstname] != '' && $_POST[firstname] != '' && $_POST[firstname] != '' && $_POST[firstname] != '') {
     
    // now we insert it into the database
     
     //Check if typeSelector is set.
     
    if($_POST['typeSelector'] != '') {
         
    $type $_POST['typeSelector'];
     } else {
         
    $type $_POST[shade];
     }
     
         
    $insert "INSERT INTO users (username, password, firstname, lastname, age, gender, email, actor)
                 VALUES ('"
    .$_POST['username']."', '".$_POST['pass']."', '$_POST[firstname]', '$_POST[lastname]', '$_POST[age]', '$_POST[gender]', '$_POST[email]', '$type')";
         
    $add_member mysql_query($insert);
         
         echo <<<EOF
         <h1>Registered</h1>
     <p>Thank you, you have registered - you may now login</a>.</p>
    EOF;

         } else {
             echo 
    "Please fill in all of the required fields.";
         } 

     } 
     else 
     {    
     
    ?>

     <?php include("links.php"); ?>


     <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="agreeform" onSubmit="return defaultagree(this)" method="post">
     <table border="0">
     <tr><td colspan="2"><h1>Register</h1></td></tr> 
     <tr><td>Username:</td><td>
     <input type="text" name="username" maxlength="60">
     </td></tr>
     <tr><td>Password:</td><td>
     <input type="password" name="pass" maxlength="20">
     </td></tr>
     <tr><td>Confirm Password:</td><td>
     <input type="password" name="pass2" maxlength="20">
     </td></tr>
      <tr><td>First name:</td><td>
     <input name="firstname" type="text" maxlength="15">
     </td></tr>
      <tr><td>Last name:</td><td>
     <input name="lastname" type="text" maxlength="15">
     </td></tr>
      <tr><td>Age:</td><td>
      <select name="age">
    <?php $i 1; while($i <= 110) { echo "<option value=\"$i\">$i</option>"$i++; } ?>
    </select>

     <tr><td>Gender:</td><td>
      <input type="radio" name="gender" value="Male" id="Male">Male
    <input type="radio" name="gender" value="Female" id="Female">Female <br />
     </td></tr>


       <tr><td>Email:</td><td>
     <input name="email" type="text" maxlength="30">
     </td></tr>

        <tr><td>Actor/Backstage?:</td><td>
      <input type="radio" name="shade" value="Actor" id="actor" onclick="chgType()">Actor 
    <input type="radio" name="shade" value="Backstageworker" id="backstage" onclick="chgType()">Backstage worker <br /> 


    <select name="typeSelector" id="typeSelector" style="visibility: hidden">
    <option>Set mover</option>
    <option>Sound</option>
    </select>
    <br /><br /><br />
    <input name="agreecheck" type="checkbox" onClick="agreesubmit(this)" id="checky" disabled="true"><b>I agree to the  <a href="terms.php" onclick="disableField()" target="_blank">terms and conditions</a></b><br>



     </td></tr>
     <tr><th colspan="2"><input type="submit" name="submit" value="Register" disabled></th></tr> </table>
     </form>

    <script type="text/javascript">
    function chgType() {
        var actor = document.getElementById('actor');
        var backstage = document.getElementById('backstage');
        
        if(backstage.checked === true) {
            document.getElementById('typeSelector').style.visibility = 'visible';
        } else {
            document.getElementById('typeSelector').style.visibility = 'hidden';
        }
    }
    </script>
     <?php
     
    }
     
    ?>



    </body>

    </html>
    I haven't changed much except for this bit

    PHP Code:
    [PHP](!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['firstname'] | !$_POST['lastname'] |  !$_POST['age'] |  !$_POST['gender'] |  !$_POST['email'] | !$type 
    [/PHP]

    If any of the field haven't been filled out then it should come up with a message. But even if I do fill out all the fields it still comes up with the message.

    Any help?

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Nothing is stored in the variable $type before the condition is called. In OOP, the exclamation mark before a variable in a conditional indicates the variable is not set.

    Try this:
    PHP Code:
    (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['firstname'] | !$_POST['lastname'] |  !$_POST['age'] |  !$_POST['gender'] |  !$_POST['email'] ) 
    - Josh

  3. #3
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Smile

    Thanks, it works now!

Bookmarks

Posting Permissions

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