Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 42

Thread: Php login/registration error

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

    Default

    Thank you so much. THis is absaloutly amazing. Just one last thing. Could you please show me how I can modify the actor and director into a radio button so they are either an actor or a backstage worker. then if they select backstage worker. it comes up with a thing (dropdown menu like AGE) which gives you options like setmover lighting sound etc.

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

    Default

    I'm not sure I understand. Do you mean that you want to replace the director value with backstage worker?

    That's easy to do, just change the value of the radio button to "backstage worker".

    As for having a drop-down menu appear, that could be done in JavaScript. Here's a small example that should work:
    Code:
    <script type="text/javascript">
    function chgType(obj) {
    if(obj.checked === true) {
    document.getElementById('typeSelector').visibility = 'visible';
    } else {
    document.getElementById('typeSelector').visibility = 'hidden';
    }
    </script>
    ...insert that within your <HEAD> tags.

    And modify your table row to include this. Just add more option tags with the innerHTML of whatever you want the other values to be.
    Code:
      <tr><td>Actor/Director?:</td><td>
     <input type="password" name="actor" value="actor" maxlength="10" selected="selected"> Actor<br>
      <input type="password" name="actor" value="backstage worker" maxlength="10"> Backstage worker.
    
    <select name="typeSelector" id="typeSelector" style="visibility: hidden">
    <option>Set mover</option>
    <option>Sound</option>
    </select>
    
     </td></tr>
    The select menu will be hidden when the option for backstage worker is not selected, and appear when it is.

    Also, since we have a new field here, we'll need to modify the PHP code to check if the value of the field is set. If it is, we'll override the old _POST value of the 'actor' field.

    PHP Code:
    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[actor];
     }
     
         
    $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.";
         } 

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

    Default

    Hi thanks for all your help.


    what I mean is instead of having actor and as password fields I would like to have them as radio buttons

    PHP Code:
     Do you wish to work as an actor or as a backstage worker <br /> 
    <
    input type="radio" name="shade" value="dark">Actor
    <input type="radio" name="shade" value="light">Backstage worker <br />
    </
    form
    Then if they select back stage worker. A drop down comes up and they can select what type of backstage work. such as set mover etc.

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

    Default

    The code that I posted before should do what you're trying to accomplish.

    Unless I'm missing something, I understood that you want to have two radio buttons: actor and backstage worker.

    When backstage worker is selected, a drop-down menu appears with the options of set mover, lights, etc.

    Please be more specific as to what you're trying to do if this isn't the case.

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

    Default

    "CREATE TABLE users(
    id INT NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(id),
    username VARCHAR(30),
    password VARCHAR(30),
    firstname VARCHAR(30),
    lastname VARCHAR(30),
    age VARCHAR(30),
    gender VARCHAR(30),
    email VARCHAR(30),
    actor VARCHAR(30))"

    I'm trying to make a sql table. This dosen't work. Any help would be great

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

    Default

    PHP Code:
    <?php 

     mysql_connect
    ("localhost""****""***") or die(mysql_error()); 
     
    mysql_select_db("****") or die(mysql_error()); 


     
    //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'] ) {
             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[actor];
     }
     
         
    $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 
     {    
     
    ?>
    age, gender, email, actor/director, first name, Last name

     <?php include("links.php"); ?>
     <form action="<?php echo $_SERVER['PHP_SELF']; ?>" 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="10">
     </td></tr>
      <tr><td>First name:</td><td>
     <input name="lastname" type="text" maxlength="10">
     </td></tr>
      <tr><td>Last name:</td><td>
     <input name="firstname" type="text" maxlength="10">
     </td></tr>
      <tr><td>Age:</td><td>
      <select name="age">
    <?php $i 1; while($i <= 110) { echo "<option value=\"$i\">$i</option>"$i++; } ?>
    </select>
     </td></tr>
       <tr><td>Email:</td><td>
     <input name="email" type="text" maxlength="10">
     </td></tr>
     <tr><td>Confirm Password:</td><td>
     <input type="password" name="pass2" maxlength="10">
     </td></tr>
        <tr><td>Actor/Director?:</td><td>
     <input type="radio" name="shade" value="Actor">Actor 
    <input type="radio" name="shade" value="Backstageworker">Backstage worker <br /> 


    <select name="typeSelector" id="typeSelector" style="visibility: hidden">
    <option>Set mover</option>
    <option>Sound</option>
    </select>

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

     <?php
     
    }
     
    ?>
    <html>

    <head>
    <body style="background-color:lightgreen">

    <script type="text/javascript">
    function chgType(obj) {
    if(obj.checked === true) {
    document.getElementById('typeSelector').visibility = 'visible';
    } else {
    document.getElementById('typeSelector').visibility = 'hidden';
    }
    </script>
    </head>
    <body>

    </body>

    </html>
    Also, is this what the finale code should look like because I tried it and everything worked except the are you an actor/backstage if you are back stage a menu comes down with a list of backstage jobs. Thankyou so much for the help you've given

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

    Default

    Why doesn't that SQL code work? What error are you getting? It could be that the table `users` already exists and that's the error that you're getting. In that case, you need to drop `users` first and then create your new table.

    Try this:
    Code:
    DROP TABLE `users`;
    
    CREATE TABLE users(
    id INT NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(id),
    username VARCHAR(30),
    password VARCHAR(30),
    firstname VARCHAR(30),
    lastname VARCHAR(30),
    age VARCHAR(30),
    gender VARCHAR(30),
    email VARCHAR(30),
    actor VARCHAR(30))
    I made a couple of mistakes with the code I gave you before (I guess I was kind of tired yesterday) and that's why the backstage worker menu wasn't working. Sorry about that.

    I forgot to set the onclick attributes and I also did not write the script properly.

    Your code has a lot of HTML errors too. You have multiple <body> and <head> tags, some of which execute after the body is completed. Also, you changed the field name of "actor" to "shade". I modified the PHP to reflect that change.

    Here is the revised code:
    PHP Code:
    <html>

    <head>
    <body style="background-color:lightgreen">
    <?php 

     mysql_connect
    ("localhost""****""***") or die(mysql_error()); 
     
    mysql_select_db("****") or die(mysql_error()); 


     
    //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'] ) {
             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']; ?>" 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="10">
     </td></tr>
      <tr><td>First name:</td><td>
     <input name="lastname" type="text" maxlength="10">
     </td></tr>
      <tr><td>Last name:</td><td>
     <input name="firstname" type="text" maxlength="10">
     </td></tr>
      <tr><td>Age:</td><td>
      <select name="age">
    <?php $i 1; while($i <= 110) { echo "<option value=\"$i\">$i</option>"$i++; } ?>
    </select>
     </td></tr>
       <tr><td>Email:</td><td>
     <input name="email" type="text" maxlength="10">
     </td></tr>
     <tr><td>Confirm Password:</td><td>
     <input type="password" name="pass2" maxlength="10">
     </td></tr>
        <tr><td>Actor/Director?:</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>

     </td></tr>
     <tr><th colspan="2"><input type="submit" name="submit" value="Register"></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>

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

    Default

    Thankyou so much. The drop down box works. It's so awesome!

    However, this error comes up every time I try to submit the form

    Internal Server Error
    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, webmaster@randomhelp4you.heliohost.org and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


    --------------------------------------------------------------------------------

    Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/0.9.8e-fips-rhel5 mod_mono/2.6.3 FrontPage/5.0.2.2635 mod_bwlimited/1.4 mod_auth_passthrough/2.1 mod_wsgi/3.3 Python/2.7.1 Server at randomhelp4you.heliohost.org Port 80


    Any help?

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

    Default

    Actually now it's not coming up with the error but their is another problem.

    making an account is working fine but when I try and login it says the information I entered is incorrect. I think it's a problem with the password.

    The md5 for james is b4cc344d25a2efe540adbf2678e2304c
    But on my database with that password it says b4cc344d25a2efe540adbf2678e230

    b4cc344d25a2efe540adbf2678e2304c
    b4cc344d25a2efe540adbf2678e230
    would that cause a problem like that. If so how should I fix it.

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

    Default

    You set your database field "password" to VARCHAR(30) (meaning that it will only put in the first 30 characters of any entry.

    Typically, people that use VARCHAR set it to 255 characters. md5-encrypted hashes are 32 characters.

    Change your "password" field to accept more characters, and that should solve your problem.

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
  •