Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 42

Thread: Php login/registration error

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

    Default

    Do you have a link to the page so I can see exactly what's wrong?
    - Josh

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

    Default

    No problem actually shows up on the page. It's only the information that's being inserted into the database.

    http://randomhelp4you.heliohost.org/...tabaseedit.php

    Thats the registration page that the form is on. I'm not actually using the information submitted yet so I can't really show you. If theirs anything I can do to help, please tell me.

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

    Default

    Have the script print the variable $type somewhere, and tell me what the value is when you submit it under the conditions that you described. The code looks like it should work just fine.
    - Josh

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

    Default

    when I select setmover it prints setmover
    when I select sound it prints sound
    when I select actor it prints setmover

    PHP Code:
     //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 
    $type;
         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 
     {    
     
    ?> 
    I added in this bit

    PHP Code:
    echo $type

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

    Default

    Try replacing this:
    PHP Code:
    if($_POST['typeSelector'] != '') {
         
    $type $_POST['typeSelector'];
     } else {
         
    $type $_POST[shade];
     } 
    With this:
    PHP Code:
    if($_POST[shade] == 'Backstageworker') {
    $type $_POST[typeSelector];
    } else {
    $type $_POST[shade];

    - Josh

  6. #36
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Yep, it works now. Thanks for all your help JShor!

  7. #37
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Okay, one more thing.

    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'] )  
         {

             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[shade] == 'Backstageworker') {
    $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 
    $type;
         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>Are you interested in backstage work or onstage?:</td><td>
      <input type="radio" name="shade" value="Actor" id="actor" onclick="chgType()">Actor 
    <input type="radio" name="shade" value="Backstage" id="backstage" onclick="chgType()">Backstage worker
    <input type="radio" name="shade" value="Both" id="both" onclick="chgType()">Both<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>
    In the code I added in this bit

    PHP Code:
    <input type="radio" name="shade" value="Both" id="both" onclick="chgType()">Both<br /> 
    So that they can select that they are interested in both. But then the original code dosen't work. When you select sound or set mover it just says $type prints Backstage.

    Any help would be great!

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

    Default

    Then you would have to rewrite that same condition to accept the value of both, as well as backstageworker from shade.

    PHP Code:
    if($_POST[shade] == 'Backstageworker' || $_POST[shade] == 'Both') { 
    - Josh

  9. #39
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Thanks JShor. When I select sound or setmover, $type still prints Backstage.

    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'] )  
         {

             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[shade] == 'Backstageworker' || $_POST[shade] == 'Both') {
    $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 
    $type;
         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>Are you interested in backstage work or onstage?:</td><td>
      <input type="radio" name="shade" value="Actor" id="actor" onclick="chgType()">Actor 
    <input type="radio" name="shade" value="Backstage" id="backstage" onclick="chgType()">Backstage worker
    <input type="radio" name="shade" value="Both" id="both" onclick="chgType()">Both<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>
    Last edited by keyboard; 09-06-2011 at 11:37 PM.

  10. #40
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

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
  •