Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include("conf-inc.php");
- //nak check sama ada username dah digunakan ke belum
- function usernameTaken($uname){
- global $conn;
- if(!get_magic_quotes_gpc()){
- $uname = addslashes($uname);
- }
- $sql = "select demo_uname from demouser where demo_uname = '$uname'";
- $result = mysql_query($sql,$conn);
- return (mysql_numrows($result) > 0);
- }
- //Inserts data dalam database arr
- function insertNewUser($demouser){
- global $conn;
- $fname = mysql_escape_string($demouser['demo_fname']);
- $lname = mysql_escape_string($demouser['demo_lname']);
- $add1 = mysql_escape_string($demouser['demo_add1']);
- $country = mysql_escape_string($demouser['demo_country']);
- $kod = mysql_escape_string($demouser['demo_kod']);
- $state = mysql_escape_string($demouser['demo_state']);
- $email = mysql_escape_string($demouser['demo_email']);
- $uname = mysql_escape_string($demouser['demo_uname']);
- $password = mysql_escape_string($demouser['demo_password']);
- $ip = $_SERVER['REMOTE_ADDR'];
- $sql = "INSERT INTO $db.demouser (demo_fname, demo_lname, demo_add1, demo_country, demo_kod, demo_state, demo_email, demo_uname, demo_password, demo_ip ,demo_acct) VALUES ('$fname','$lname','$add1','$country','$kod','$state','$email','$uname','$password','$ip',20)";
- return mysql_query($sql,$conn);
- }
- //fungsi nak display message samaada berjaya or tak
- function displayStatus(){
- $uname = $_SESSION['reguname'];
- if($_SESSION['regresult']){
- ?>
- <h1>Registered!</h1>
- <p>Thank you <b><? echo $uname; ?></b>, your information has been added to the database, you may now</p>
- <?
- }
- else{
- ?>
- <h1>Registration Failed</h1>
- <p>We're sorry, but an error has occurred and your registration for the username <b><? echo $uname; ?></b>, could not be completed.<br>
- Please try again at a later time.</p>
- <?
- }
- unset($_SESSION['reguname']);
- unset($_SESSION['registered']);
- unset($_SESSION['regresult']);
- }
- if(isset($_SESSION['registered'])){
- //hanya akan kuar bila percubaan utk register arr
- ?>
- <html>
- <title>Registration Page</title>
- <body>
- <? displayStatus(); ?>
- </body>
- </html>
- <?
- return;
- }
- /**
- * Determines whether or not to show to sign-up form
- * based on whether the form has been submitted, if it
- * has, check the database for consistency and create
- * the new account.
- */
- if(isset($_POST['f_submit'])){
- /* Make sure all fields were entered */
- if(!$_POST['uname'] || !$_POST['password']){
- die('You didn\'t fill in a required field.');
- }
- /* Spruce up username, check length */
- $_POST['uname'] = trim($_POST['uname']);
- if(strlen($_POST['uname']) > 30){
- die("Sorry, the username is longer than 30 characters, please shorten it.");
- }
- /* Check if username is already in use */
- if(usernameTaken($_POST['uname'])){
- $use = $_POST['uname'];
- die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one.");
- }
- /* Add the new account to the database */
- $md5pass = md5($_POST['password']);
- $_SESSION['reguname'] = $_POST['uname'];
- $_SESSION['regresult'] = insertNewUser($_POST['uname'], $md5pass);
- $_SESSION['registered'] = true;
- echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
- return;
- }
- /**
- * This is the page with the sign-up form, the names
- * of the input fields are important and should not
- * be changed.
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement