here is my code sorry its kinda long ^^; and sloppy im what you might call a newbie at php:Fatal error: Call to undefined function: error_message() in /home/sensi/public_html/Testing/signup.php on line 47
Code: Select all
<?php
session_start();
include("config.php");
include("header.php");
if(isset($_SESSION['id'])){
echo "<center>Hey your already logged in!<br>Why do you need to sign up again?</center>";
} else {
//selects table to insert data into
$table = "users";
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database) or die ("Could not select database because ".mysql_error());
//if they signed up.
if($_GET['action'] == 'signup') {
$name = $_POST['name'];
$username = $_POST['username'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['repassword'];
$terms = $_POST['terms'];
$gender = $_POST['gender'];
$age = $_POST['age'];
$check1 = $_POST['check1'];
$check2 = $_POST['check2'];
$check3 = $_POST['check3'];
//one or more fields were left blank
if(!isset($name) || !isset($username) || !isset($email) || !isset($password) || !isset($password2) || !isset($gender) || !isset($age)){
error_message('<b><font size="3" color="red">One or more required fields were left blank!</font></b>');
}
//if name is longer then 20 character then display message
if(strlen($name)>20) {
error_message('<b><font size="3" color="red">Name was to long</font></b>');
}
//password to small?
if(strlen($password)<5) {
error_message('<b><font size="3" color="red">Your password is to short please try again.</font></b>');
}
//password to big?
if(strlen($password)>30) {
error_message('<b><font size="5" color="red">Your password is to long please try again.</font></b>');
}
//e-mail to big
if(strlen($email)>50) {
error_message('<b><font size="3" color="red">E-mail was to long please try another email.</font></b>');
}
//passwords match?
if($password != $password2) {
error_message('<b><font size="3" color="red">Passwords <u>MUST</u> match.</font></b>');
}
//terms checked?
if(!isset($terms)) {
error_message('<b><font size="3" color="red">You can not join unless you agree to the terms of service.</font></b>');
}
//1st and 3rd checked?
if(!isset($check1) || !isset($check3) || isset($check2)) {
error_message('<b><font size="3" color="red">Please check the appropriate boxes.</font></b>');
}
// check if the username is taken
$check = "select id from $table where username = '".$_POST['username']."';";{
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
error_message('<b><font size="3" color="red">Sorry, the username is already taken.</font></b>');
}
}
//Sucess, insert the data
//html for sucessfull signup
// is the $from email address in valid format?
// check if email syntax is valid
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) )
{
// create the MD5 hash
$secret_code = 'secret';
$formatted_email = preg_replace("/(-|\@|\.)/", "", $email);
$secret = md5("$secret_code $formatted_email");
$mail_body ="
Welcome to Sensipets
we would like to welcome you to the sensipets community
your login information is
Username: $username
Password: $password
Validation number: $secret
Please log in and validate your account";
mail($email, "Validation Email", $mail_body, "From: postmaster@sensipets.com\n");
echo "<META HTTP-EQUIV=Refresh CONTENT='4; URL=index.php'> Please check your email <b>$email</b> for the test validation message";
//special variables
$joined = date("m/d/Y");
$sc = 2500;
$level = 0;
$pets = 0;
$description = "Hello this is my profile";
//insert user data into db
$insert = mysql_query("insert into $table values (
'NULL',
'".$name."',
'".$username."',
'". md5($password) ."',
'".$age."',
'".$email."',
'".$gender."',
'".$sc."',
'".$joined."',
'".$level."',
'".$pets."',
'".$description."',
'".$secret."',
'0',
'http://www.sensipets.com/Testing/images/avatars/default.gif',
'This is my Siggy',
'0',
'0')") or die("Could not insert data because ".mysql_error());
} else {
print("Sorry, this email address: <b>$email</b> doesn't seem to be in the right format.");
}
} else {
//html for sign up
echo "<body topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>";
echo "<table border=2>";
echo "<FORM action='".$_SERVER['PHP_SELF']."?action=signup' method='post'>";
echo "<tr><td>";
echo "Username:<br>";
echo "(Maximum is 25 characters)";
echo "</td><td>";
echo "<input type='text' name='username' size='25'>";
echo "</td></tr>"; //125
echo "<tr><td>";
echo "Password:<br>";
echo "(Minimum 5 characters)";
echo "</td><td>";
echo "<input type='password' name='password' size='25'>";
echo "</td></tr>";
echo "<tr><td>";
echo "Retype Password:";
echo "</td><td>";
echo "<input type='password' name='repassword' size='25'>";
echo "</td></tr>";
echo "<tr><td>";
echo "E-mail:";
echo "</td><td>";
echo "<input type='text' name='email' size='25'>";
echo "</td></tr>";
echo "<tr><td>";
echo "Name:<br>";
echo "(First and Last)";
echo "</td><td>";
echo "<input type='text' name='name' size='25'>";
echo "</td></tr>";
echo "<tr><td>";
echo "Do you agree to the Terms of Service?";
echo "</td><td>";
echo "Yes <input type='checkbox' name='terms' value='yes'>";
echo "</td></tr>";
echo "<tr><td>";
echo "Gender:";
echo "</td><td>";
echo "<select name=gender class='drop'><option>Undecided</option>";
echo "<option value=Male>Male</option>";
echo "<option value=Female>Female</option>";
echo "</select>";
echo "</td></tr>";
echo "<tr><td>";
echo "Your age:";
echo "</td><td>";
echo "<select name=age class='drop'>";
echo "<option value=''>???</option>";
$i=5;
While($i>=5 AND $i<=100) {
echo "<option value='$i'>$i</option>";
$i++;
}
echo "</td></tr>";
echo "<tr><td>";
echo "Security purposes";
echo "</td><td>";
echo "Please check 1st and 3rd box<br>";
echo "<input type='checkbox' name='check1' value='check1'>";
echo "<input type='checkbox' name='check2' value='check2'>";
echo "<input type='checkbox' name='check3' value='check3'>";
echo "</td></tr>";
echo "<tr><td colspan=2>";
echo "<center>";
//take out the double slash below to allow users to sign up.
echo "<input type='submit' value='Sign-up' name='submit'>";
echo "</center>";
echo "</tr></td>";
echo "</form>";
echo "</table>";
}
//html for signing up error
function error_message($message) {
echo "<body topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>";
echo $message;
echo "<table border=2>";
echo "<FORM action='".$_SERVER['PHP_SELF']."?action=signup' method='post'>";
echo "<tr><td>";
echo "Username:<br>";
echo "(Maximum is 25 characters)";
echo "</td><td>";
echo "<input type='text' name='username' size='25'>";
echo "</td></tr>";
echo "<tr><td>";
echo "Password:<br>";
echo "(Minimum 5 characters)";
echo "</td><td>";
echo "<input type='password' name='password' size='25'>";
echo "</td></tr>";
echo "<tr><td>";
echo "Retype Password:";
echo "</td><td>";
echo "<input type='password' name='repassword' size='25'>";
echo "</td></tr>";
echo "<tr><td>";
echo "E-mail:";
echo "</td><td>";
echo "<input type='text' name='email' size='25'>";
echo "</td></tr>";
echo "<tr><td>";
echo "Name:<br>";
echo "(First and Last)";
echo "</td><td>";
echo "<input type='text' name='name' size='25'>";
echo "</td></tr>";
echo "<tr><td>";
echo "Did you read the Terms of Service?";
echo "</td><td>";
echo "Yes <input type='checkbox' name='terms' value='yes'>";
echo "</td></tr>";
echo "<tr><td>";
echo "Gender:";
echo "</td><td>";
echo "<select name=gender class='drop'><option>Undecided</option>";
echo "<option value=Male>Male</option>";
echo "<option value=Female>Female</option>";
echo "</select>";
echo "</td></tr>";
echo "<tr><td>";
echo "Your age:";
echo "</td><td>";
echo "<select name=age class='drop'>";
echo "<option value=''>???</option>";
$i=5;
While($i>=5 AND $i<=100) {
echo "<option value='$i'>$i</option>";
$i++;
}
echo "</td></tr>";
echo "<tr><td>";
echo "Security purposes";
echo "</tr><td>";
echo "Please check 1st and 3rd box<br>";
echo "<input type='checkbox' name='check1' value='check1'>";
echo "<input type='checkbox' name='check2' value='check2'>";
echo "<input type='checkbox' name='check3' value='check3'>";
echo "</td></tr>";
echo "<tr><td colspan=2>";
echo "<center>";
echo "<input type='submit' value='Sign-up' name='submit'>";
echo "</center>";
echo "</tr></td>";
echo "</form>";
echo "</table>";
include("footer.php");
}}
?>