This is guide mostly for website tools and code, for example CMS or registration scripts.
There can also be tools.
Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators
by matty13 on Sun Feb 17, 2008 1:25 pm
Does anyone have a basic register script to work with osRose?
-
matty13
- Jelly Bean
-
- Posts: 26
- Joined: Sun Sep 02, 2007 11:58 pm
-
by Rifke on Mon Feb 18, 2008 6:15 pm
Comments are welcome-
- <?php
- # Written by Rifke (mitch.rifke@telenet.be)
- # Written for osrose community
- # You can use or distrubute it as long as you leave credits
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <title>Registration</title>
- </head>
-
- <body>
- <?php
- // Settings - start [Cut HERE]
- // you can copy this part into your config file if you have one, else edit it here
- $Setting['Age_Restriction'] = true; // Required to fill in a age!
- $Setting['Permitted_Age'] = 16; // Permitted age.
- $Setting['Require_Email'] = true; // Required to fill in a email addres!
- $Setting['MySQL_Host'] = 'localhost'; // MySQL host
- $Setting['MySQL_Port'] = '3306'; // MySQL port
- $Setting['MySQL_User'] = 'user'; // MySQL user
- $Setting['MySQL_Pass'] = 'pass'; // MySQL pass
- $Setting['MySQL_mndb'] = 'osrose'; // MySQL database
- // Settings - end [Cut HERE]
-
- $Submitted = false; // used to see if a form is submitted
- if ( ($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['Submit'] == 'Submit') ) {
- function protect($string) {
- if ( get_magic_quotes_gpc() == 1 ) return $string;
- else return mysql_real_escape_string($string);
- }
- // validation
- if ( strlen(trim($_POST['username'])) > 24 ) $Error[] = 'Please fill in a username with less than 24 characters!';
- if ( strlen(trim($_POST['username'])) <= 3 ) $Error[] = 'Please fill in a username with more than 3 characters!';
- if ( strlen(trim($_POST['password'])) == 0 ) $Error[] = 'Please fill in a password!';
- elseif ( strlen(trim($_POST['password2'])) == 0 ) $Error[] = 'Please confirm your password!';
- elseif ( $_POST['password'] != $_POST['password2'] ) $Error[] = 'Passwords do not match';
- if ( $Setting['Require_Email'] === true ) {
- if ( strlen(trim($_POST['email'])) == 0 ) $Error[] = 'Incomplete email address!';
- elseif ( strlen(trim($_POST['suffix'])) == 0 ) $Error[] = 'Incomplete email address!';
- elseif ( strlen(trim($_POST['ext'])) == 0 ) $Error[] = 'Incomplete email address!';
- else $email = $_POST['email'].'@'.$_POST['suffix'].'.'.$_POST['ext'];
- }
- if ( ($Setting['Age_Restriction'] === true) && ($_POST['age'] < $Setting['Permitted_Age']) ) $Error[] = 'You do not meet the minimum age requirements to sign up!';
- if ( $Error ) {
- echo 'The following error(s) need to be fixed before you can continue:<br />';
- echo implode('<br />', $Error);
- } else {
- // make database connection -start
- // make a database connection remove this if you already have one running.
- $ident = @mysql_connect($Setting['MySQL_Host'].':'.$Setting['MySQL_Port'],$Setting['MySQL_User'],$Setting['MySQL_Port']);
- if ( $ident === false ) $Error[] = 'Could not establish connection with database server';
- if ( @mysql_select_db($Setting['MySQL_mndb']) === false ) $Error[] = 'Could not establish connection with database';
- // make database connection -end
-
- // check if username exits
- $sql = "SELECT id FROM accounts WHERE username='%s' ";
- $sql = sprintf($sql,protect($_POST['username']));
- $qry = @mysql_query($sql);
- if ( $qry === false ) $Error[] = 'I am sorry but we could not proceed with registering your account due a database issue!';
- elseif ( mysql_num_rows($qry) == 1 ) $Error[] = 'I am sorry but this account name is already been taken!';
- if ( $Setting['Require_Email'] === true ) {
- $sql = "SELECT id FROM accounts WHERE email='%s' ";
- $sql = sprintf($sql,protect($email));
- $qry = @mysql_query($sql);
- if ( $qry === false ) $Error[] = 'I am sorry but we could not proceed with registering your account due a database issue!';
- elseif ( mysql_num_rows($qry) == 1 ) $Error[] = 'I am sorry but this email address is already been taken!';
- }
- if ( $Error ) {
- echo 'The following database error(s) occourd:<br />';
- echo implode('<br />', $Error);
- } else {
- // Register your account!
- if ( $Setting['Require_Email'] === true ) {
- $sql = "INSERT INTO accounts (username,password,email) VALUES ('%s','%s','%s')";;
- $sql = sprintf($sql,protect($_POST['username']),md5($_POST['password']),protect($email));
- } else {
- $sql = "INSERT INTO accounts (username,password) VALUES ('%s','%s')";;
- $sql = sprintf($sql,protect($_POST['username']),md5($_POST['password']));
- }
- $qry = @mysql_query($sql);
- if ( $qry === false ) {
- echo 'I am sorry but we could not proceed with registering your account due a database issue!';
- } else {
- echo 'Your account has been successfully registred!';
- $Submitted = true;
- }
- }
- }
- }
- if ( $Submitted === false ) {
- function repost($var) {
- if ( $_POST[$var] == NULL ) { return ''; }
- else {
- if ( get_magic_quotes_gpc() == 1 ) return stripslashes($_POST[$var]);
- else return $string;
- }
- }
- ?>
- <form action="" method="post">
- <table width="100%" border="0" cellspacing="5" cellpadding="2">
- <tr>
- <th width="100" scope="row">Username:</th>
- <td><input name="username" type="text" id="username" value="<?php echo repost('username'); ?>" /></td>
- </tr>
- <tr>
- <th scope="row">Password:</th>
- <td><input name="password" type="password" id="password" value="<?php echo repost('password'); ?>" /></td>
- </tr>
- <tr>
- <th scope="row">Password (again): </th>
- <td><input name="password2" type="password" id="password2" value="<?php echo repost('password2'); ?>" /></td>
- </tr>
- <?php
- if ( $Setting['Require_Email'] === true ) {
- ?>
- <tr>
- <th scope="row">Email:</th>
- <td><input name="email" type="text" id="email" value="<?php echo repost('email'); ?>" />
- <strong>@</strong>
- <input name="suffix" type="text" id="suffix" size="10" value="<?php echo repost('suffix'); ?>" />
- <strong>.</strong>
- <input name="ext" type="text" id="ext" size="5" value="<?php echo repost('ext'); ?>" /></td>
- </tr>
- <?php
- }
- if ( $Setting['Age_Restriction'] === true ) {
- ?>
- <tr>
- <th scope="row">Age:</th>
- <td><input name="age"type="text" id="age" size="5" value="<?php echo repost('age'); ?>" /></td>
- </tr>
- <?php
- }
- ?>
- <tr>
- <th scope="row"> </th>
- <td><input type="submit" name="Submit" value="Submit" /></td>
- </tr>
- </table>
- </form>
- <?php
- }
- ?>
- </body>
- </html>
-
- Attachments
-
- registration_script.txt
- (6.28 KiB) Downloaded 608 times
-
Rifke
- Pero pero
-
- Posts: 719
- Joined: Thu Aug 09, 2007 3:01 pm
- Location: Belgium
-
by karl19 on Thu Apr 12, 2012 8:06 am
got this problem even i set the database setting correctly
The following database error(s) occourd:
Could not establish connection with database server
-
karl19
- Little soul
-
- Posts: 9
- Joined: Sat Mar 31, 2012 1:03 pm
-
Return to PHP / Web Guides, Scripts and tools.
Users browsing this forum: No registered users and 6 guests