FirefoxyChic
29th November 10, 11:49 PM
Hi all -
Working on a new site - This time I have to add a registration and login area. I found a very simple and straighforward bit of php code from about.com and decided to implement it on the site. I am not a programmer by any means and merely dabble in simple php. I really need some help and advice from some of you programming gurus here at welovecss.com to get this site running!! THANKS IN ADVANCE!!:):)
A- is this code good using cookies or should I use sessions?
B- If I use sessions instead how difficult would it be to change my existing code
<div class="register">
<?php
// Connects to your Database
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") 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['password'] | !$_POST['confirmpw'] | !$_POST['lastname_maman'] | !$_POST['firstname_maman'] | !$_POST['email'] | !$_POST['phone']) {
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['password'] != $_POST['confirmpw']) {
die('Your passwords did not match. ');
}
// here we encrypt the password and add slashes if needed
$_POST['password'] = md5($_POST['password']);
if (!get_magic_quotes_gpc()) {
$_POST['password'] = addslashes($_POST['password']);
$_POST['username'] = addslashes($_POST['username']);
}
// now we insert it into the database
$insert = "INSERT INTO users (lastname_maman, firstname_maman, dob_maman, email, rue, code_postal, city, country, phone, profession_maman, children, lastname_papa, firstname_papa, dob_papa, profession_papa, username, password)
VALUES (
'".$_POST['lastname_maman']."',
'".$_POST['firstname_maman']."',
'".$_POST['dob_maman']."',
'".$_POST['email']."',
'".$_POST['rue']."',
'".$_POST['code_postal']."',
'".$_POST['city']."',
'".$_POST['country']."',
'".$_POST['phone']."',
'".$_POST['profession_maman']."',
'".$_POST['children']."',
'".$_POST['lastname_papa']."',
'".$_POST['firstname_papa']."',
'".$_POST['dob_papa']."',
'".$_POST['profession_papa']."',
'".$_POST['username']."',
'".$_POST['password']."')";
$add_member = mysql_query($insert);
?>
<h1>Registered</h1>
<p>Thank you, you have registered - you may now <a href="login.php">login</a>.</p>
<?php
}
else
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h5>Maman </h5>
<table width="100%">
<tr><td width="28%">
<label for="lastname_maman">Nom <span class="requiredlabel">(requis)</span></label>
</td><td width="22%"><input name="lastname_maman" type="text" id="lastname_maman" value="" class="required" />
</td>
<td width="25%">
<label for="firstname_maman">Prénom<span class="requiredlabel">(requis)</span></label>
</td>
<td width="25%"><input name="firstname_maman" type="text" id="firstname_maman" value="" class="required"/>
</td>
</tr>
<tr><td colspan="2"></td><td colspan="2"></td></tr><tr><td>
<label for="dob_maman">Année de naissance</label>
</td><td><input name="dob_maman" type="text" id="dob_maman" value="" class="date"/>
</td>
<td><label for="email">Adresse e-mail <span class="requiredlabel">(requis)</span></label>
</td><td><input type="text" name="email" id="email" value="" class="required email" />
</td>
<tr><td colspan="4"></td></tr><tr>
<td>
<label for="rue">Numéro et nom de rue</label>
</td><td><input name="rue" type="text" id="rue" value="" />
</td>
<td><label for="code_postal">Code postal</label></td>
<td><input name="code_postal" type="text" id="code_postal" value="" /></tr><tr><td>
</td>
<tr><td colspan="4"></td></tr><tr><td>
<label for="city">Ville</label>
</td><td><input name="city" type="text" id="city" value="" />
</td>
<td>
<label for="country">Pays</label>
</td>
<td colspan="3"><input name="country" type="text" id="country" value="" />
</td></tr>
<tr><td colspan="2"></td>
<td colspan="2"></td><tr ><td>
<label for="phone">Téléphone <span class="requiredlabel">(requis)</span></label>
</td><td><input name="phone" type="text" id="phone" value="" class="required phone"/>
<td>
<label for="profession_maman">Profession</label>
</td><td colspan="3"><input name="profession_maman" type="text" id="profession_maman" value="" />
</td></tr><tr><td colspan="2"></td>
<td colspan="2"></td><tr ><td>
<label for="children">Nombre d'enfants (nés et à naître)</label>
</td><td><input name="children" type="text" id="children" value="" />
</td></tr>
<tr><td colspan="4"> </td></tr>
<tr><td colspan="4"><div class="dottedline"></div><h5>Papa</h5></td></tr>
<tr><td width="28%">
<label for="lastname_papa">Nom</label>
</td><td width="22%"><input name="lastname_papa" type="text" id="lastname_papa" value="" />
</td>
<td width="25%">
<label for="firstname_papa">Prénom</label>
</td>
<td width="25%"><input name="firstname_papa" type="text" id="firstname_papa" value="" />
</td>
</tr>
<tr><td colspan="2"></td><td colspan="2"></td></tr><tr><td>
<label for="dob_papa">Année de naissance</label>
</td><td><input name="dob_papa" type="text" id="dob_papa" value="" />
</td><td>
<label for="profession_papa">Profession</label>
</td><td colspan="3"><input name="profession_papa" type="text" id="profession_papa" value="" />
</td></tr>
<tr><td colspan="4"> </td></tr>
<tr><td colspan="4"><div class="dottedline"></div></td></tr>
<td>
<label for="username"> Nom d'utilisateur <span class="requiredlabel">(requis)</span></label>
</td><td><input name="username" type="text" id="username" value="" class="required"/>
</td>
</tr><tr><td colspan="2"></td><td colspan="2"></td></tr><tr><td>
<label for="password">Mot de passe <span class="requiredlabel">(requis - jusqu'à 7 caractéres)</span></label>
</td><td><input name="password" type="password" id="password" value="" maxlength="20" class="required"/>
</td>
<td><label for="confirmpw">Confirmer Mot de passe <span class="requiredlabel">(requis)</span></label>
</td><td><input name="confirmpw" type="password" id="confirmpw" value="" class="required"/>
</td>
</tr>
</table>
<p class="submit"><input type="submit" name="submit" class="submit" value="Submit »" /></p>
</form>
<?php
}
?>
</div>
Working on a new site - This time I have to add a registration and login area. I found a very simple and straighforward bit of php code from about.com and decided to implement it on the site. I am not a programmer by any means and merely dabble in simple php. I really need some help and advice from some of you programming gurus here at welovecss.com to get this site running!! THANKS IN ADVANCE!!:):)
A- is this code good using cookies or should I use sessions?
B- If I use sessions instead how difficult would it be to change my existing code
<div class="register">
<?php
// Connects to your Database
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") 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['password'] | !$_POST['confirmpw'] | !$_POST['lastname_maman'] | !$_POST['firstname_maman'] | !$_POST['email'] | !$_POST['phone']) {
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['password'] != $_POST['confirmpw']) {
die('Your passwords did not match. ');
}
// here we encrypt the password and add slashes if needed
$_POST['password'] = md5($_POST['password']);
if (!get_magic_quotes_gpc()) {
$_POST['password'] = addslashes($_POST['password']);
$_POST['username'] = addslashes($_POST['username']);
}
// now we insert it into the database
$insert = "INSERT INTO users (lastname_maman, firstname_maman, dob_maman, email, rue, code_postal, city, country, phone, profession_maman, children, lastname_papa, firstname_papa, dob_papa, profession_papa, username, password)
VALUES (
'".$_POST['lastname_maman']."',
'".$_POST['firstname_maman']."',
'".$_POST['dob_maman']."',
'".$_POST['email']."',
'".$_POST['rue']."',
'".$_POST['code_postal']."',
'".$_POST['city']."',
'".$_POST['country']."',
'".$_POST['phone']."',
'".$_POST['profession_maman']."',
'".$_POST['children']."',
'".$_POST['lastname_papa']."',
'".$_POST['firstname_papa']."',
'".$_POST['dob_papa']."',
'".$_POST['profession_papa']."',
'".$_POST['username']."',
'".$_POST['password']."')";
$add_member = mysql_query($insert);
?>
<h1>Registered</h1>
<p>Thank you, you have registered - you may now <a href="login.php">login</a>.</p>
<?php
}
else
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h5>Maman </h5>
<table width="100%">
<tr><td width="28%">
<label for="lastname_maman">Nom <span class="requiredlabel">(requis)</span></label>
</td><td width="22%"><input name="lastname_maman" type="text" id="lastname_maman" value="" class="required" />
</td>
<td width="25%">
<label for="firstname_maman">Prénom<span class="requiredlabel">(requis)</span></label>
</td>
<td width="25%"><input name="firstname_maman" type="text" id="firstname_maman" value="" class="required"/>
</td>
</tr>
<tr><td colspan="2"></td><td colspan="2"></td></tr><tr><td>
<label for="dob_maman">Année de naissance</label>
</td><td><input name="dob_maman" type="text" id="dob_maman" value="" class="date"/>
</td>
<td><label for="email">Adresse e-mail <span class="requiredlabel">(requis)</span></label>
</td><td><input type="text" name="email" id="email" value="" class="required email" />
</td>
<tr><td colspan="4"></td></tr><tr>
<td>
<label for="rue">Numéro et nom de rue</label>
</td><td><input name="rue" type="text" id="rue" value="" />
</td>
<td><label for="code_postal">Code postal</label></td>
<td><input name="code_postal" type="text" id="code_postal" value="" /></tr><tr><td>
</td>
<tr><td colspan="4"></td></tr><tr><td>
<label for="city">Ville</label>
</td><td><input name="city" type="text" id="city" value="" />
</td>
<td>
<label for="country">Pays</label>
</td>
<td colspan="3"><input name="country" type="text" id="country" value="" />
</td></tr>
<tr><td colspan="2"></td>
<td colspan="2"></td><tr ><td>
<label for="phone">Téléphone <span class="requiredlabel">(requis)</span></label>
</td><td><input name="phone" type="text" id="phone" value="" class="required phone"/>
<td>
<label for="profession_maman">Profession</label>
</td><td colspan="3"><input name="profession_maman" type="text" id="profession_maman" value="" />
</td></tr><tr><td colspan="2"></td>
<td colspan="2"></td><tr ><td>
<label for="children">Nombre d'enfants (nés et à naître)</label>
</td><td><input name="children" type="text" id="children" value="" />
</td></tr>
<tr><td colspan="4"> </td></tr>
<tr><td colspan="4"><div class="dottedline"></div><h5>Papa</h5></td></tr>
<tr><td width="28%">
<label for="lastname_papa">Nom</label>
</td><td width="22%"><input name="lastname_papa" type="text" id="lastname_papa" value="" />
</td>
<td width="25%">
<label for="firstname_papa">Prénom</label>
</td>
<td width="25%"><input name="firstname_papa" type="text" id="firstname_papa" value="" />
</td>
</tr>
<tr><td colspan="2"></td><td colspan="2"></td></tr><tr><td>
<label for="dob_papa">Année de naissance</label>
</td><td><input name="dob_papa" type="text" id="dob_papa" value="" />
</td><td>
<label for="profession_papa">Profession</label>
</td><td colspan="3"><input name="profession_papa" type="text" id="profession_papa" value="" />
</td></tr>
<tr><td colspan="4"> </td></tr>
<tr><td colspan="4"><div class="dottedline"></div></td></tr>
<td>
<label for="username"> Nom d'utilisateur <span class="requiredlabel">(requis)</span></label>
</td><td><input name="username" type="text" id="username" value="" class="required"/>
</td>
</tr><tr><td colspan="2"></td><td colspan="2"></td></tr><tr><td>
<label for="password">Mot de passe <span class="requiredlabel">(requis - jusqu'à 7 caractéres)</span></label>
</td><td><input name="password" type="password" id="password" value="" maxlength="20" class="required"/>
</td>
<td><label for="confirmpw">Confirmer Mot de passe <span class="requiredlabel">(requis)</span></label>
</td><td><input name="confirmpw" type="password" id="confirmpw" value="" class="required"/>
</td>
</tr>
</table>
<p class="submit"><input type="submit" name="submit" class="submit" value="Submit »" /></p>
</form>
<?php
}
?>
</div>