// ------------------------------------------------------------- // File Register.html // Desc : Just a form that submits data to the Member.html page // All database testing happens there. // Note : This page is only ever called from the Members page // ------------------------------------------------------------- // Include the session settings and start the session require_once("SessionSettings.php"); session_start(); require_once ("Admin/DatabaseConnection.php"); require_once ("Admin/Crypt.php"); require_once ("Admin/emailer.php"); require_once ("NavBar.php"); // Create databse connection $dbHandle=ConnectToMySql(); ConnectToDatabase("",$dbHandle); $Command=""; $MSG=""; $DisplayName=""; $Email=""; $ConfirmEmail=""; $Password=""; $ConfirmPassword=""; $Address=""; $Postcode=""; // Fetch paramaters from Get and Post arrays if (isset( $_POST['Command'])) $Command = trim( $_POST['Command'] ); if (isset( $_POST['DisplayName'])) $DisplayName = trim( $_POST['DisplayName'] ); if (isset( $_POST['Email'])) $Email = trim( $_POST['Email'] ); if (isset( $_POST['ConfirmEmail'])) $ConfirmEmail = trim( $_POST['ConfirmEmail'] ); if (isset( $_POST['Password'])) $Password = trim( $_POST['Password'] ); if (isset( $_POST['ConfirmPassword'])) $ConfirmPassword = trim( $_POST['ConfirmPassword']); if (isset( $_POST['Address'])) $Address = trim( $_POST['Address'] ); if (isset( $_POST['Postcode'])) $Postcode = trim( $_POST['Postcode'] ); // Lets just check the person is already logged in otherwise send them to the members page if (isset($_SESSION['UserID'])) { $UserID= $_SESSION['UserID']; // A session ID is set so lets check it exists $dbResult = mysql_query("select * from users where ID=".$UserID." limit 1", $dbHandle); // If the id is valid then relocate to the members area if ($dbResult && mysql_num_rows( $dbResult)) { header("Location: Members.html"); exit(); } } if ($Command=="Register") { // Ok lets check the data if ( $DisplayName=="" || strlen($DisplayName)<3 ) $MSG="Error: Display Name must be at least 3 characters long."; else if ( $Email=="" || strlen($Email)<3 || $Email!=$ConfirmEmail) $MSG="Error: The email fields were filled in incorrectly."; else if ( $Password=="" || strlen($Password)<3 || $Password!=$ConfirmPassword) $MSG="Error: The password fields were filled in incorrectly."; // If MSG=="" then everything is still ok so we proceed with the database test if ($MSG=="") { $CryptEmail = EncryptString( $Email , "Dallas" ); $dbResult = mysql_query( "SELECT * FROM users WHERE Email='".$CryptEmail."' LIMIT 1 ",$dbHandle); // If it exists then this email already has an account if (mysql_num_rows($dbResult)) $MSG="Error: There is already an account registered to this email address."; else { // Lets test the display name is unique $dbResult = mysql_query( "SELECT * FROM users WHERE DisplayName='".addslashes($DisplayName)."' LIMIT 1 ",$dbHandle); if (mysql_num_rows($dbResult)) $MSG="Error: The Display Name you have chosen is already in use. Please choose another."; else { // All is good so encrypt and enter $CryptPassword = EncryptString( $Password , "Dallas" ); $dbResult = mysql_query(" INSERT INTO users ( DisplayName , Email , Password , Address , Postcode, Avatar, Registered ) VALUES ( '".addslashes($DisplayName)."', '".$CryptEmail."', '".$CryptPassword."', '".addslashes($Address)."', '".addslashes($Postcode)."', 'Generic.jpg', ".time()." ) ", $dbHandle); // If something went wrong then prepare msg if (!$dbResult || !mysql_affected_rows( $dbHandle ) ) $MSG="Error: Database Error - Your account could not be created."; else { // Fetch userid and insert into session $UserID = mysql_insert_id(); $_SESSION['UserID'] = $UserID; // Now lets send the welcome email // Create the emailer object $Emailer = new CEmailer(); // Setup constant email data $Emailer->SetFromName("The Bee Gees Story"); $Emailer->SetSubject("Welcome to our Community"); $Emailer->SetFromAddress("contactus@beegeesstory.co.uk"); // Use curl to fetch price $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.beegeesstory.co.uk/NewsletterMedia/WelcomeNewAccount.html" ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, ""); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $Message = curl_exec($ch); curl_close($ch); $Emailer->SetBodyText ( "You need an HTML enabled email client to view this email. But don't worry, you can view the email by clicking here http://www.beegeesstory.co.uk/NewsletterMedia/WelcomeNewAccount.html",$Message ); $Emailer->SetToName("Member"); $Emailer->SetToAddress($Email); $Emailer->Send(); // Relocate to members area header("Location: Members.html"); exit(); } } } } } OpenPage("Register","","Register for a new Account - Jive Talkin Community"); ?>