Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I made a simple Register script!
#1
Opinions? And yes, you can use this if you would like.

1. I know it doesn't REALLY register a user
2. I now know 'echo' is faster than 'print'. Stop bothering me about that! >.<

Register.html:

[lua]
<html>
<title>Register!</title>
<body>
<div><p>Please fill out this form to register:</div></p>
<form action="handle_reg.php" mehtod="post">

<p>Email: <input type="text" name="email" size="30" /></p>
<p>Password: <input type="password" name="password" size="30" /></p>
<p>Comfirm Password: <input type="password" name="confirm" size="20" /></p>

<p>Date Of Birth:
<select name="month">
<option value="">Month</option>
<option value="1">January</option>
<option value="2">Febuary</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>

<?php
for ($d = 1; $d <= 31; $d++) {
print "<option value=\"$d\">$d</option>\n";
}
?>

<input type="text" name="year" value="YYYY" size="4" /></p>

<p>Favorit Color:
<select name="color">
<option value="">Pick one</option>
<option value="yellow">Yellow</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="purple">Purple</option>
<option value="gray/white">Gray/White</option>
</select></p>

<input type="submit" name="submit" value="Register" />

</form>
</div>
</body>
</html>
[/lua]

handle_reg.php:

[lua]
<html>
<title>Registration</title>

<style type="text/css" media="screen">
.error { color: red; }
</style>

<h1>Registration Results</h1>

<?php
$okay = TRUE;

//Validate color
if ($_POST['color'] == 'red') {
print '<p style="color:red;">Red is your favorite color.</p>';
} elseif ($_POST['color'] == 'yellow') {
print '<p style="color:yellow;">Yellow is your favorite color.</p>';
} elseif ($_POST['color'] =='blue') {
print '<p style="color:blue;">Your favorite color is blue.</p>';
} elseif ($_POST['color'] =='green') {
print '<p style="color:green;">Your favorite color is green.</p>';
} elseif ($_POST['color'] =='purple') {
print '<p style="color:purple;">Your favorite color is purple.</p>';
} elseif ($_POST['color'] =='gray/white') {
print '<p style="color:gray;">Your favorite colors is gray and white</p>';
} else {
print '<p class="error">Please select your favorite color.</p>';
$okay = FALSE;
}


print '<p>You have entered your birthday as $birthday</p>';

//validate email address
if (empty($_POST['emial'])) {
print '<p class="error">Oops! Your forgot your email!</p>';
$okay = FALSE;
}

//error on password
if (empty($_POST['password'])) {
print '<p class="error">Oops! Your forgot your password!</p>';
$okay = FALSE;
}

if ($_POST['password'] != $_POST['confirm']) {
print '<p class="error">Your passwords do not match!</p>';
$okay = FALSE;
}

//Vailidate year
if ( is_numeric($_POST['year']) AND (strlen($_POST['year']) == 4) ) {
//check that they were born before 2009
if ($_POST['year'] >= 2009) {
print '<p class="error"> Either you come from the future, or you entered your birthdate wrong!</p>';
} else {
$birthday .= $_POST['year'];
}

} else {
print '<p class="error">Please enter your birthdate as four digits.</p>';
$okay = FALSE;
}

$birthday = "";
if (is_numeric($_POST['month'])) {
$birthday = $_POST['month'] . '-';
} else {
print '<p class="error">Please select the month you were born</p>';
$okay = FALSE;
}

if (is_numeric($_POST['day'])) {
$birthday .= $_POST['day'] . '-';
} else {
print '<p class="error">Please select the day you were born</p>';
$okay = FALSE;

//If there were no errors, This is what comes up.
if ($okay) {
print '<p>You have been succsessfully registered! (but not really lol).</p>;
}

?>
</body>
</html>
[/lua]
I forgot to mention:

I know I need work on my CSS and HTML. I can't find anything to learn from that's good enough. Sad
[Image: chaosthegreat.png]
Reply
#2
Errm... shouldn't you make it so you can only use an email once?
[Image: AmZJnA9.png]
Reply
#3
(07-16-2011, 02:17 AM)Glome Wrote: Errm... shouldn't you make it so you can only use an email once?

Shhhh.... This will be good if Jacob_ uses it..
Reply
#4
(07-16-2011, 03:56 AM)Fish Wrote:
(07-16-2011, 02:17 AM)Glome Wrote: Errm... shouldn't you make it so you can only use an email once?

Shhhh.... This will be good if Jacob_ uses it..

We already have one.
Hello
Reply
#5
It would be bad if Jacob_ used it

My username would be Glome'; DROP TABLE users; --
[Image: AmZJnA9.png]
Reply
#6
(07-16-2011, 04:13 AM)Glome Wrote: It would be bad if Jacob_ used it

My username would be Glome'; DROP TABLE users; --

So this register is not legit?
Hello
Reply
#7
(07-16-2011, 04:18 AM)Ashely Wrote:
(07-16-2011, 04:13 AM)Glome Wrote: It would be bad if Jacob_ used it

My username would be Glome'; DROP TABLE users; --

So this register is not legit?

Oh it has a few things wrong with it but it would work.

Except it's not connected to a database so it wouldn't actually register the users. Oh and if it was it isn't very secure.
[Image: AmZJnA9.png]
Reply
#8
@Glome, all it does is echo the data you entered, it doesn't store anything...

[lua]if ($_POST['color'] == 'red') {
print '<p style="color:red;">Red is your favorite color.</p>';
} elseif ($_POST['color'] == 'yellow') {
print '<p style="color:yellow;">Yellow is your favorite color.</p>';
} elseif ($_POST['color'] =='blue') {
print '<p style="color:blue;">Your favorite color is blue.</p>';
} elseif ($_POST['color'] =='green') {
print '<p style="color:green;">Your favorite color is green.</p>';
} elseif ($_POST['color'] =='purple') {
print '<p style="color:purple;">Your favorite color is purple.</p>';
} elseif ($_POST['color'] =='gray/white') {
print '<p style="color:gray;">Your favorite colors is gray and white</p>';
} else {
print '<p class="error">Please select your favorite color.</p>';
$okay = FALSE;
}[/lua]

I believe that can be shortened to:

[lua]if (isset($_POST['color']) {
print '<p style="color:blue;">Your favorite color is '.$_POST['color'].'</p>';
} else {
print '<p class="error">Please select your favorite color.</p>';
$okay = FALSE;
}[/lua]


:3
Reply
#9
(07-16-2011, 06:31 AM)noob007 Wrote: @Glome, all it does is echo the data you entered, it doesn't store anything...

[lua]if ($_POST['color'] == 'red') {
print '<p style="color:red;">Red is your favorite color.</p>';
} elseif ($_POST['color'] == 'yellow') {
print '<p style="color:yellow;">Yellow is your favorite color.</p>';
} elseif ($_POST['color'] =='blue') {
print '<p style="color:blue;">Your favorite color is blue.</p>';
} elseif ($_POST['color'] =='green') {
print '<p style="color:green;">Your favorite color is green.</p>';
} elseif ($_POST['color'] =='purple') {
print '<p style="color:purple;">Your favorite color is purple.</p>';
} elseif ($_POST['color'] =='gray/white') {
print '<p style="color:gray;">Your favorite colors is gray and white</p>';
} else {
print '<p class="error">Please select your favorite color.</p>';
$okay = FALSE;
}[/lua]

I believe that can be shortened to:

[lua]if (isset($_POST['color']) {
print '<p style="color:blue;">Your favorite color is '.$_POST['color'].'</p>';
} else {
print '<p class="error">Please select your favorite color.</p>';
$okay = FALSE;
}[/lua]


:3
Nice job.
Hello
Reply
#10
@Noob007

I said if it WAS connected to the database it wouldn't be secure.
[Image: AmZJnA9.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)