Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2009, 01:50 PM
Registered User
 
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Username Script

Hi, I have all the tables in my MySQL database but i cant get this script to work, it keep failing before like 46, Please can someone have a look?

PHP Code:
<?php
    
//Start session
    
session_start();
    
    
//Include database connection details
    
require_once('config.php');
    
    
//Array to store validation errors
    
$errmsg_arr = array();
    
    
//Validation error flag
    
$errflag false;
    
    
//Connect to mysql server
    
$link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
    if(!
$link) {
        die(
'Failed to connect to server: ' mysql_error());
    }
    
//Select database
    
$db mysql_select_db(DB_DATABASE);
    if(!
$db) {
        die(
"Unable to select database");
    }
    
    
//Function to sanitize values received from the form. Prevents SQL injection
    
function clean($str) {
        
$str = @trim($str);
        if(
get_magic_quotes_gpc()) {
            
$str stripslashes($str);
        }
        return 
mysql_real_escape_string($str);
    }
    
    
//Sanitize the POST values
    
$firstname clean($_POST['firstname']);
    
$lastname clean($_POST['lastname']);
    
$user clean($_POST['user']);
    
$password clean($_POST['password']);
    
$passwordc clean($_POST['passwordc']);
    
$email clean($_POST['email']);
    
$emailc clean($_POST['emailc']);
    
$post $_POST['post'];
    
$twoletter $_POST['twoletter'];
    
$phone $_POST['phone'];
    
    
//Input Validations
    
if($firstname == '') {
        
$errmsg_arr[] = 'First name missing';
        
$errflag true;
    } 
    if(
$lastname == '') {
        
$errmsg_arr[] = 'Last name missing';
        
$errflag true;
    }
    if(
$user == '') {
        
$errmsg_arr[] = 'Login ID missing';
        
$errflag true;
    }
    if(
$password == '') {
        
$errmsg_arr[] = 'Password missing';
        
$errflag true;
    }
    if(
$passwordc == '') {
        
$errmsg_arr[] = 'Confirm password missing';
        
$errflag true;
    }
    if( 
strcmp($password$passwordc) != ) {
        
$errmsg_arr[] = 'Passwords do not match';
        
$errflag true;
    }
    if(
$email == '') {
        
$errmsg_arr[] = 'email Missing';
        
$errflag true;
    }
    if(
$emailc == '') {
        
$errmsg_arr[] = 'Confirm email missing';
        
$errflag true;
    }
    if( 
strcmp($email$emailc) != ) {
        
$errmsg_arr[] = 'email do not match';
        
$errflag true;
    }
    
    
//Check for duplicate login ID
    
if($user != '') {
        
$qry "SELECT * FROM members WHERE username = '$user'";
        
$result mysql_query($qry);
        if(
$result) {
            if(
mysql_num_rows($result) > 0) {
                
$errmsg_arr[] = 'Username ID already in use';
                
$errflag true;
            }
            @
mysql_free_result($result);
        }
        else {
            die(
"Query failed");
        }
    } 
    
// BETA KEY
    // $bkey = ''.$post.'-'.$phone.'-'.$twoletter.'';
    //If there are input validations, redirect back to the registration form
    
if($errflag) {
        
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
        
session_write_close();
        
header("location: registration.php");
        exit();
    }
    
//FILE NAME
    
$filename 'file/'.$user.'/';
    
//Create INSERT query
    
$qry "INSERT INTO hewparg_users(firstname, lastname, user, password, email, filedir, bkey)
 VALUES('
$firstname','$lastname','$user','".md5($_POST['password'])."','$email','$filename','$bkey')";
    
$result = @mysql_query($qry);
    
    
    
    
/* DIRECTORY MAKING */
    
     
mkdir("file/".$user.""0777);
    
    
    
//Check whether the query was successful or not
    
if($result) {
        
header("location: login.php");
        exit();
    }else {
        die(
"Query failed");
    }
?>
 
Old May 11th, 2009, 05:03 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

What exactly is the error message you are getting and can you provide some example data you are putting in?
 
Old May 12th, 2009, 09:36 AM
Registered User
 
Join Date: May 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When i enter the data to the form, Which is

FORM
HTML Code:
<form action="registration-process.php" method="post">
          <div align="left"><br />
            </div>
              <hr align="left" />
          <div align="right"><strong>First Name :</strong> 
            <input name="firstname" type="text" />
            
            <br />
            <strong>Last Name :</strong>
            <input name="lastname" type="text" />
            
            <strong><br />
              Email Address :</strong>
             <input name="email" type="text" />
            
            
             <strong><br />
               Confirm Email Address : </strong>
            <input name="emailc" type="text" />
            </div>
              <HR align="left" />
          
          <div align="right"><strong>Username :</strong>
            <input name="user" type="text" />
            
            
            <br />
            <strong>Password : </strong>
            <input name="password" type="password" />
            
            
            <strong><br />
              Confirm Password :</strong>
              <input name="passwordc" type="password" />
            </div>
              <hr align="left" />
          <div align="right"><span class="style3">First 4 Letters or Numbers of </span><strong>Post Code : </strong>
            <input name="post" type="text" />
            <strong><br />
              Phone Area Code :</strong>
            <input name="phone" type="text" />
            
            <strong><br />
              First two letters of name :</strong>
             <input name="twoletter" type="text" />
             <br />
            
            
            
             <input name="Register" type="submit" value="Register" />
            </div>
          </form>

And then is goes to the process page, and it just comes up Query failed
and the only place i got that is on line 97

Which the code before then is
PHP Code:
<?php
    
//Start session
    
session_start();
    
    
//Include database connection details
    
require_once('config.php');
    
    
//Array to store validation errors
    
$errmsg_arr = array();
    
    
//Validation error flag
    
$errflag false;
    
    
//Connect to mysql server
    
$link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
    if(!
$link) {
        die(
'Failed to connect to server: ' mysql_error());
    }
    
    
//Select database
    
$db mysql_select_db(DB_DATABASE);
    if(!
$db) {
        die(
"Unable to select database");
    }
    
    
//Function to sanitize values received from the form. Prevents SQL injection
    
function clean($str) {
        
$str = @trim($str);
        if(
get_magic_quotes_gpc()) {
            
$str stripslashes($str);
        }
        return 
mysql_real_escape_string($str);
    }
    
    
//Sanitize the POST values
    
$firstname clean($_POST['firstname']);
    
$lastname clean($_POST['lastname']);
    
$user clean($_POST['user']);
    
$password clean($_POST['password']);
    
$passwordc clean($_POST['passwordc']);
    
$email clean($_POST['email']);
    
$emailc clean($_POST['emailc']);
    
$post clean($_POST['post']);
    
$twoletter clean($_POST['twoletter']);
    
$phone clean($_POST['phone']); 
    
    
//Input Validations
    
if($firstname == '') {
        
$errmsg_arr[] = 'First name missing';
        
$errflag true;
    } 
    if(
$lastname == '') {
        
$errmsg_arr[] = 'Last name missing';
        
$errflag true;
    }
    if(
$user == '') {
        
$errmsg_arr[] = 'Login ID missing';
        
$errflag true;
    }
    if(
$password == '') {
        
$errmsg_arr[] = 'Password missing';
        
$errflag true;
    }
    if(
$passwordc == '') {
        
$errmsg_arr[] = 'Confirm password missing';
        
$errflag true;
    }
    if( 
strcmp($password$passwordc) != ) {
        
$errmsg_arr[] = 'Passwords do not match';
        
$errflag true;
    }
    if(
$email == '') {
        
$errmsg_arr[] = 'email Missing';
        
$errflag true;
    }
    if(
$emailc == '') {
        
$errmsg_arr[] = 'Confirm email missing';
        
$errflag true;
    }
    if( 
strcmp($email$emailc) != ) {
        
$errmsg_arr[] = 'email do not match';
        
$errflag true;
    }
    
    
//Check for duplicate login ID
    
if($user != '') {
        
$qry "SELECT * FROM members WHERE username = '$user'";
        
$result mysql_query($qry);
        if(
$result) {
            if(
mysql_num_rows($result) > 0) {
                
$errmsg_arr[] = 'Username ID already in use';
                
$errflag true;
            }
            @
mysql_free_result($result);
        }
        else {
            die(
"Query failed");
        }
    }

There is no error message





Similar Threads
Thread Thread Starter Forum Replies Last Post
Change the order of client script / server script rupen ASP.NET 2.0 Basics 3 April 16th, 2009 01:41 PM
how to get username and password somarya08 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 7 April 1st, 2009 03:02 PM
Username Changes Ben Horne Forum and Wrox.com Feedback 2 March 12th, 2004 12:20 PM
Call and run CGI script from a PHP script ... how? dbruins BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 June 10th, 2003 03:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.