Help with registration script !!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • silmana
    New Member
    • Aug 2007
    • 19

    Help with registration script !!

    hello, i have this problem that i cannot bound the registration script to the login script, what i mean is that when i register, i cannot login in the login script although the information comes to the database. Could someone help me with it just create a registration script (username,passw ord,confirm password) and bound it to my login script so that when i register i can log in?

    here is my database table:

    CREATE TABLE users (
    username VARCHAR(30) NOT NULL,
    password VARCHAR(40) NOT NULL,
    PRIMARY KEY (username)
    );

    and here is my login script:
    <?php
    // startar sessionen
    session_start() ;

    if (isset($_POST["anvandarID "]) && isset($_POST["losenord"])) {

    // ansluter till databasen
    $opendb = mysql_connect(" localhost", "username", "password") or die(mysql_error ());
    mysql_select_db ("username") or die(mysql_error ());

    // anslut till databasen med separata filer
    //include "config.php ";
    //include "connect_databa se.php";

    $anvandarID = $_POST["anvandarID "];
    $password = sha1($_POST["losenord"]);

    // kontrollerar om kombinationen av användarnamn och lösenord finns i MySQL-tabellen
    $sql = "SELECT username FROM users WHERE username = '$anvandarID' AND password = '$password'";

    // hämtar information från den angivna tabellen
    $result = mysql_query($sq l) or die(mysql_error ());

    if (mysql_num_rows ($result) == 1) {
    // ange den session som lagrar rätt inloggningsuppg ifter
    $_SESSION["inloggning "] = true;

    // efter rätt inloggning förflyttas användaren till den skyddade sidan
    header("Locatio n: skyddad_sida.ph p");
    exit;
    }
    // om användarnamn och lösenord är fel lagras meddelandetexte n i variabeln
    else {$felmeddelande = "Du har angivit fel användarnamn eller lösenord!";}


    mysql_close($op endb);
    }
    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <style type="text/css">
    <!--
    body {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px;}
    table {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; letter-spacing: 2px;}
    h2 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 24px; color: #336633; letter-spacing: 2px; font-weight: normal;}
    .kantlinje {border: 1px solid #99cc00;}
    .formularfalt {border: 1px solid #99CC00; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; padding: 5px; border: 1px solid #99CC00;}
    -->
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Logga in</title>
    </head>

    <body>
    <h2>Logga in </h2>
    <p>Inloggning med flera anv&auml;ndare som kontrolleras mot en MySQL-tabell </p>
    <p>
    <?php
    echo "<strong><f ont color='#ff0000' >" . $felmeddelande . "</font></strong>";
    ?>
    </p>
    <form action="" method="post" name="loginform ">
    <table border="0" cellpadding="5" cellspacing="0" bgcolor="#ccff6 6" class="kantlinj e">
    <tr><td>Anv&aum l;ndarnamn</td>
    <td><input name="anvandarI D" type="text" class="formular falt"></td></tr>
    <tr><td>L&ouml; senord</td>
    <td><input name="losenord" type="password" class="formular falt"></td></tr>
    <tr><td>&nbsp ;</td>
    <td><input type="submit" value="Logga in"></td></tr>
    </table>
    </form>
    </body>
    </html>

    once again, i want you to make a registration page that would fit in my login page

    //Thanks
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    HAve you made a registration script?

    Regards

    Comment

    • silmana
      New Member
      • Aug 2007
      • 19

      #3
      yes here it is, could you please make it fit the login script.

      I want the registration script containing username,passwo rd,confirm password and email.

      could you bound everything together and show the all the scripts(login script, database table, registration script. thanks

      <?php
      // Connects to your Database
      mysql_connect(" localhost", "user", "password") or die(mysql_error ());
      mysql_select_db ("user") 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('Fyll i alla uppgifter!');
      }

      // checks if the username is in use
      if (!get_magic_quo tes_gpc()) {
      $_POST['username'] = addslashes($_PO ST['username']);
      }
      $usercheck = $_POST['username'];
      $check = mysql_query("SE LECT 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('Användarna mnet '.$_POST['username'].' är upptaget.');
      }

      // this makes sure both passwords entered match
      if ($_POST['pass'] != $_POST['pass2']) {
      die('Du angav inte samma lösenord, försök igen');
      }

      // here we encrypt the password and add slashes if needed
      $_POST['pass'] = md5($_POST['pass']);
      if (!get_magic_quo tes_gpc()) {
      $_POST['pass'] = addslashes($_PO ST['pass']);
      $_POST['username'] = addslashes($_PO ST['username']);
      }

      // now we insert it into the database
      $insert = "INSERT INTO users (username, password)
      VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
      $add_member = mysql_query($in sert);
      ?>


      <h1>Registere d</h1>
      <p>Tack, du är registrerad - och kan nu logga in</a>.</p>
      <?php
      }
      else
      {
      ?>


      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <table border="0">
      <tr><td>Använda rnamn:</td><td>
      <input type="text" name="username" maxlength="60">
      </td></tr>
      <tr><td>Lösenor d:</td><td>
      <input type="password" name="pass" maxlength="10">
      </td></tr>
      <tr><td>Bekräft a lösenord:</td><td>
      <input type="password" name="pass2" maxlength="10">
      </td></tr>
      <tr><th colspan=2><inpu t type="submit" name="submit" value="Registre ra"></th></tr> </table>
      </form>

      <?php
      }
      ?>

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Please read the forum guidelines on how to post questions (code tags)

        Regards.

        I don't understand what you mean by 'bind' them together..

        Comment

        • silmana
          New Member
          • Aug 2007
          • 19

          #5
          WHEN I REGISTER I WANT TO BE ABLE TO LOG IN, in the login script??? and i cannot do that , why?

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by silmana
            WHEN I REGISTER I WANT TO BE ABLE TO LOG IN, in the login script??? and i cannot do that , why?
            Because you have no idea how to use PHP?

            I don't know.

            And i'm certainly not going to help you with an attitude like that.

            Comment

            Working...