FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


php+mysql password / login screen





st_jimi
i need help.

i want a simple php login/ sign up screen, i just want it to be a email adress and password, does anyone know how to install em,

plus is then possible to add them to a mailing list by them checking a terms and conditions box?

any help thx
Roald
Do you know PHP and sql? A sign up is like this:
HTML code:
Code:
<form action="register.php" method="post">
E-mail address:<input type="text" name="email" size="40" maxlength="40"><br>
password: <input type="password" name="password" size="20" maxlength="10"><br>
Newsletter: <select><option>yes</option><option>no</option></select><br>
<input type="submit" value="Register" name="register">
</form>

PHP code: (register.php)
Code:
<?php
$mail = $_POST['email'];
$pass = $_POST['password'];
$newsletter = $_POST['newsletter'];
function form($warning){
   echo "<b>$warning</b> <br>";
   echo "<form action=\"register.php\" method=\"post\">";
   echo "E-mail adress:<input type=\"text\" name=\"email\" size=\"40\" maxlength=\"40\"><br>";
   echo "password: <input type=\"password\" name=\"password\" size=\"20\" maxlength=\"10\"><br>";
   echo "Newsletter: <select name=\"newsletter\"><option>yes</option><option>no</option></select><br>";
   echo "<input type=\"submit\" value=\"Register\" name=\"register\">";
   echo "</form>";
   return;
}
if ($mail == ""){//check empty fields
   $warning = "You have to fill in the required fields.";
   form($warning);
   exit();
}
if ($pass == ""){//check empty fields
   $warning = "You have to fill in the required fields.";
   form($warning);
   exit();
}
if (!ereg("^.+@.+\\..+$",$mail))//check email
{
   $warning = "Fill in a valid email address";
   form($warning);
   exit();
}
$connection = mysql_connect($host,$user,$password)
   or die ("Unable to connect to the server.");
$db = mysql_select_db($database, $connection)
   or die ("Unable to select database.");
$sql = "SELECT email FROM member WHERE email='$mail'";
$result = mysql_query($sql)
   or die("Could not execute query.");
$num = mysql_num_rows($result);//check email address doesn't exists already
if ($num > 0){
   $warning = "Email address exists already, plaese try an other one.";
   form($warning);
   exit();
}
else {//insert values in database
   $sql = "INSERT INTO member (email, password, newsletter) VALUES ('$mail','$pass','$newsletter')";
   mysql_query($sql)
      or die("Could not execute query.");
}
?>
Of course you have to change the variables $host, $password and $database
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.