Reply
Enter Date of Birth
Old 07-01-2007, 01:09 PM Enter Date of Birth
Junior Talker

Posts: 3
Hello guys,

I'm not sure if this is a coding mistake, or a mistake setting up the database. So i'll give you both.

Basicaly, it's a registration form... And it doesn't work... Not helpful.

Quote:
<?php
if (isset($_POST['submitted'])) {

$errors = array();
require_once ('mysql_connect.php');

if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($_POST['username']))) ) {
$user = mysql_real_escape_string($_POST['username']);
$query = "SELECT username FROM users WHERE username = '$user'";
$result = @mysql_query($query);
$num = @mysql_num_rows($result);

if ($num> 0) {
$errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';
} else {
$username = mysql_real_escape_string($_POST['username']);
}
} else {
$errors[] = '<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
}
if (!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})', stripslashes(trim($_POST['email'])) )) {
$errors[] = '<font color="red">Please provide a valid email address.</font>';
} else {
$email = mysql_real_escape_string($_POST['email']);
}

if (!empty($_POST['password1'])) {
if ($_POST['password1'] != $_POST['password2']) {
$errors[] = '<font color="red">The 2 passwords you have entered do not match.</font>';
} else {
$password = $_POST['password1'];
}
} else {
$errors[] = '<font color="red">Please provide a password.</font>';
}

if (!empty($_POST['title'])) {
} else {
$errors[] = '<font color="red">Please enter your title.</font>';
}

if (!empty($_POST['firstname'])) {
} else {
$errors[] = '<font color="red">Please enter your forname.</font>';
}
if (!empty($_POST['surname'])) {
} else {
$errors[] = '<font color="red">Please enter your surname.</font>';
}
if (!empty($_POST['day'])) {
} else {
$errors[] = '<font color="red">Please enter your date of birth.</font>';
}
if (!empty($_POST['month'])) {
} else {
$errors[] = '<font color="red">Please enter your date of birth.</font>';
}
if (!empty($_POST['year'])) {
} else {
$errors[] = '<font color="red">Please enter your date of birth.</font>';
}
if (!empty($_POST['checkbox'])) {
} else {
$errors[] = '<font color="red">Please read and agree to our terms and conditions.</font>';
}
if (!empty($_POST['checkbox2'])) {
} else {
$errors[] = '<font color="red">Please read and agree to our privacy policy.</font>';
}
if (empty($errors)) {
$a = md5(uniqid(rand(), true));
$query = "INSERT INTO users (username, email, password, active, title, firstname, surname, day, month, year) VALUES ('$username', '$email', SHA('$password'), '$a')";

$result = @mysql_query($query);

if (mysql_affected_rows() == 1) {

$body = "Thank you for registering at Toon-Army.co.uk. To activate your account, please click on this link:\n\n";
$body .= "http://www.toon-army.co.uk/activate.php?x=" . mysql_insert_id() . "&y=$a";
mail($_POST['email'], 'Registration Confirmation', $body, 'From: craig.howarth@toon-army.co.uk');

echo '<h3>Thank You!</h3>
You have been registered, an email has been sent to the address you specified before. Please check your e-mails to activate your account.';
} else {
echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>';
}

} else {
echo '<h3>Error!</h3>
The following error(s) occured:<br />';

foreach ($errors as $msg) {
echo " - <font color=\"red\">$msg</font><br />\n";
}
}
}
?>

<form action="http://www.toon-army.co.uk/register.php" method="post">
<p class="style17"><span class="style17"><span class="style17"><span class="style17"><span class="style17"><span class="style17"><span class="style17"><span class="style17"><span class="style17"><strong>Account Information:</strong><br>
<br>
<input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" size="30" maxlength="30" />
<small>Username</small></span></span></span></span></span></span></span></span></p>
<p class="style17 style17 style17 style17 style17 style17 style17 style17"><input type="password" name="password1" size="30" maxlength="40" /> <small>Password</small></p>

<p class="style17 style17 style17 style17 style17 style17 style17 style17"><input type="password" name="password2" size="30" maxlength="40" /> <small>Confirm Password</small></p>

<p class="style17 style17 style17 style17 style17 style17 style17 style17"><input type="text" name="email" size="30" maxlength="30" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /> <small>Email Address</small></p>
<p class="style17 style17 style17 style17 style17 style17 style17 style17"><strong>Personal Information:</strong></p>
<p class="style17 style17 style17 style17 style17 style17 style17 style17"><input name="title" type="text" maxlength="30"> Title
<tr class="style9">
<td class="style17 style17 style17 style17 style17 style17 style17 style17">&nbsp;</td>
<td class="style17 style17 style17 style17 style17 style17 style17 style17">
<p>
<input name="firstname" type="text" maxlength="30">
First Name</p></td>
</tr>
<tr class="style9">
<td class="style17 style17 style17 style17 style17 style17 style17 style17"><p>
<input name="surname" type="text" maxlength="30">
Surname</p>
<td class="style17 style17 style17 style17 style17 style17 style17 style17"></td>
<td class="style17 style17 style17 style17 style17 style17 style17 style17">

<input name="day" type="text" maxlength="2" size="1"> Day
<input name="month" type="text" maxlength="2" size="1"> Month
<input name="year" type="text" maxlength="4" size="3"> Year</td>
</tr>
<span class="style17 style17 style17"> <br>
Date of Birth (eg 13.02.1992)</span>
</p>
<span class="style17"></span></span>
<p class="style17 style17 style17 style17 style17 style17"> <input type="checkbox" name="checkbox" value="1">
I have read and agree to the terms and conditions.
</span></td>
</tr>
<tr class="style9">
<td class="style17 style17"><span class="style17 style17 style17 style17">
<input type="checkbox" name="checkbox2" value="1">
I have read and understood the privacy policy.</span>
<p class="style17"><span class="style17 style17 style17">
<input type="submit" name="submit" value="Register" />
</span> </p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
There is the script...

And here is the database setup.



And if it's helpful: http://www.toon-army.co.uk/register.php there is the page.
craighowarth is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 07-01-2007, 01:38 PM Re: Enter Date of Birth
Novice Talker

Posts: 5
Name: Holger Schmitz
Location: Birmingham, UK
It would be good to know, what the error exactly is.

Maybe you should omit the '@' sign in front of 'mysql_query', to see whether there is an error in the query.
__________________
Holger Schmitz -- Web Developer -- www.viventic.biz
hschmitz is offline
Reply With Quote
View Public Profile Visit hschmitz's homepage!
 
Old 07-01-2007, 02:16 PM Re: Enter Date of Birth
Junior Talker

Posts: 3
Quote:
Originally Posted by hschmitz View Post
It would be good to know, what the error exactly is.

Maybe you should omit the '@' sign in front of 'mysql_query', to see whether there is an error in the query.
It just comes up with the manual error message I put in the code:

PHP Code:
echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>'
So i'm guessing the script is fine, it just cannot put the information into the database.
craighowarth is offline
Reply With Quote
View Public Profile
 
Old 07-01-2007, 03:08 PM Re: Enter Date of Birth
Novice Talker

Posts: 5
Name: Holger Schmitz
Location: Birmingham, UK
Quote:
Originally Posted by craighowarth View Post
It just comes up with the manual error message I put in the code:

PHP Code:
echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>'
So i'm guessing the script is fine, it just cannot put the information into the database.
This means, that the number of affected rows is not equal to 1 which means there is probably an error in the query.
Your query is
PHP Code:
$query "INSERT INTO users (username, email, password, active, title, firstname, surname, day, month, year) VALUES ('$username', '$email', SHA('$password'), '$a')"
My first guess is that the number of values doesn't match the number of fields you are trying to set.

You are suppressing any error messages from the query by the use of the '@' symbol in front of the 'mysql_query'. If you omit it, like
PHP Code:
 $result mysql_query($query); 
you will probably see the full error message.
__________________
Holger Schmitz -- Web Developer -- www.viventic.biz
hschmitz is offline
Reply With Quote
View Public Profile Visit hschmitz's homepage!
 
Reply     « Reply to Enter Date of Birth
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13787 seconds with 12 queries