View Single Post
Share |
  #1 (permalink)  
Old 04-03-2007, 06:01 AM
Gukkie Gukkie is offline
Junior Member
 
Join Date: 03-31-07
Posts: 7
iTrader: 0 / 0%
adding into database problems

Hi, i am currently having some problems adding information into a database. All the validation functions work correctly. Can some1 help me out.Thanks

The table in my database is named "signup" and contains "id,uname,fname,lname,email,country,address,zipcod e,contact,datejoined,confirmkey"

The code to my add script is :

PHP Code:
    include ("auth.php");
    
$connection mysql_connect($dbhost$dbusername$dbpassword);
    
$db mysql_select_db($dbname);

  
    
$username addslashes($_POST['username']);
    
$password $_POST['password'];
    
$fname $_POST['fname'];
    
$lname $_POST['lname'];
    
$email addslashes($_POST['email']);
    
$country $_POST['country'];
    
$address $_POST['address'];
    
$zipcode $_POST['zipcode'];
    
$contact $_POST['contact'];

    
// Generate confirmation key for settings which require one
    
$confirmkey =  md5(uniqid(rand())); 

    
// CHECK FOR RESERVED USERNAMES
    
if (trim($username)=='sa' || trim($username)=='admin' || trim($username)=='test')
    {
        
$UsernameExist 1;
    }
    
    
// CHECK FOR REQUIRED FIELDS
    
if (empty($username))
    {
        print 
"<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Username field cannot be left blank!</b></font></p>";
        exit;
    }
    if (empty(
$password))
    {
        print 
"<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Password field cannot be left blank!</b></font></p>";
        exit;
    }
    
    
// this makes sure both passwords entered match
    
if ($_POST['password'] != $_POST['pass2']) {
        print 
"<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Your passwords did not match!</b></font></p>";
        exit;
    }
    
    if (empty(
$fname))
    {
        print 
"<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>First Name field cannot be left blank!</b></font></p>";
        exit;
    }
    
    if (empty(
$email))
    {
        print 
"<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Email field cannot be left blank!</b></font></p>";
        exit;
    }
    
    
// Validate Email Address String
      
$good ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
               
'@'.
               
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
               
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',
               
$email);    
    if (!
$good)
    {
        print 
"<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Email field has invalid characters!</b></font></p>";
        exit;
    }
    
    
// Validate Email Address String - FOR VALID EMAIL DOMAINS
    
$found=false;
    if (
$EmailArray!="")
    {
        for (
$ct=0;$ct<=sizeof($EmailArray)-1;$ct++)
        {
            if (
eregi($EmailArray[$ct], $email))
            {
                
$ct=sizeof($EmailArray);
                
$found=true;
            }
            else
            {
                
$found=false;
            }
        }
    }
    else
    {
        
$found true;
    }
    if (!
$found)
    {
        print 
"<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Email address does not belong to the list of allowable email domains!</b></font></p>";
        exit;
    }
    
        if (empty(
$address))
    {
        print 
"<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Address field cannot be left blank!</b></font></p>";
        exit;
    }

    
// Make sure username does not yet exist in the db
    
if ($UsernameExist>0)
    {
        print 
"<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Username already exists in the database!</b></font></p>";
        exit;
    }
    
    
// Make sure email address does not yet exist in the db
    
if ($EmailExist>0)
    {
        print 
"<p><font size=\"3\" face=\"Verdana, Arial\" color=\"#FF0000\"><b>Email address already exists in the database!</b></font></p>";
        exit;
    }
    

    
// Add new member to table signup
    
$addmember mysql_query("INSERT INTO signup VALUES    ('','$username','$fname','$lname','$email','$country','$address','$zipcode','$contact',NOW(),'$confirmkey')"); 

Last edited by Gukkie; 04-03-2007 at 06:04 AM.
 
Reply With Quote