Connecting Tech Pros Worldwide Help | Site Map

Help with registration script !!

Newbie
 
Join Date: Aug 2007
Posts: 19
#1: Mar 26 '08
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,password,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_database.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($sql) or die(mysql_error());

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

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


mysql_close($opendb);
}
?>

<!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><font color='#ff0000'>" . $felmeddelande . "</font></strong>";
?>
</p>
<form action="" method="post" name="loginform">
<table border="0" cellpadding="5" cellspacing="0" bgcolor="#ccff66" class="kantlinje">
<tr><td>Anv&auml;ndarnamn</td>
<td><input name="anvandarID" type="text" class="formularfalt"></td></tr>
<tr><td>L&ouml;senord</td>
<td><input name="losenord" type="password" class="formularfalt"></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's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: Mar 26 '08

re: Help with registration script !!


HAve you made a registration script?

Regards
Newbie
 
Join Date: Aug 2007
Posts: 19
#3: Mar 26 '08

re: Help with registration script !!


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

I want the registration script containing username,password,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_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('Användarnamnet '.$_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_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}

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


<h1>Registered</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ändarnamn:</td><td>
<input type="text" name="username" maxlength="60">
</td></tr>
<tr><td>Lösenord:</td><td>
<input type="password" name="pass" maxlength="10">
</td></tr>
<tr><td>Bekräfta lösenord:</td><td>
<input type="password" name="pass2" maxlength="10">
</td></tr>
<tr><th colspan=2><input type="submit" name="submit" value="Registrera"></th></tr> </table>
</form>

<?php
}
?>
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#4: Mar 26 '08

re: Help with registration script !!


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

Regards.

I don't understand what you mean by 'bind' them together..
Newbie
 
Join Date: Aug 2007
Posts: 19
#5: Mar 26 '08

re: Help with registration script !!


WHEN I REGISTER I WANT TO BE ABLE TO LOG IN, in the login script??? and i cannot do that , why?
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#6: Mar 26 '08

re: Help with registration script !!


Quote:

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.
Reply