Hi All,
Sorry for posting another problem but I promise this IS the last. It should be more solveable than the last.
I attempted some form validation but I seem to have made a complete mess of it. Can anyone see where I went wrong? Before I introduced the validation and regular expressions it was working fine but because I'm not really sure of this topic I made syntax errors everywhere. I would appreciate any help with this as I really want to learn.
The Form Action
PHP Code:
case 'Create Account':
        
$error=array();
        
$name = (isset($_POST['name'])) trim(? $_POST['name']) : '';
        if(empty(
$name)){
        
$error[]=urlencode('Please enter your fullname.');
        }
        
        
$email = (isset($_POST['email'])) trim(? $_POST['email']) : '';
        if(empty(
$email)){
        
$error[]=urlencode('Please enter your email.');
        if (
strpos($email".") > 0) &&
                   (
strpos($email"@") > 0)) ||
                    
preg_match("/[^a-zA-Z0-9.@_-]/"$email))
        
$error[] = urlencode('The Email address is invalid.');
        }
        
        
$username = (isset($_POST['username'])) trim(? $_POST['username']) : '';
        if(empty(
$username)){
        
$error[]=urlencode('Please enter a username.');
        if (
strlen($username)) < 5){
         
$error[] = urlencode('Usernames must be at least 5 characters long.');
        }
        
        
// check if username already is registered
        
$sql 'SELECT username FROM site_users WHERE username = "' .
        
$username '"';
        
$result mysql_query($sql$db) or die(mysql_error());
        if (
mysql_num_rows($result) > 0) {
        
$errors[] = 'Username ' $username ' is already registered.';
        
$username '';
    }
        
$age = (isset($_POST['age'])) trim(? $_POST['age']) : '';
        if(empty(
$age)){
        
$error[]=urlencode('Please enter your age.');
        if (!
is_numeric($age)) {
            
$error[] = urlencode('Please enter a numeric value for age.');
        } else if (
$age 18 || $age 110) {
            
$error[] = urlencode('Please enter age between 18 and 110.');
        }
        
        
$phone = (isset($_POST['phone'])) trim(? $_POST['phone']) : '';
        if(empty(
$phone)){
        
$error[]=urlencode('Please enter your phone number.');
        if (!
is_numeric($phone)) {
            
$error[] = urlencode('Please enter a numeric value for phone number.');
        }
        
        
$address = (isset($_POST['address'])) trim(? $_POST['address']) : '';
        if(empty(
$address)){
        
$error[]=urlencode('Please enter your address.');
        }
        
        
$county = (isset($_POST['county'])) trim(? $_POST['county']) : '';
        if(empty(
$county)){
        
$error[]=urlencode('Please enter your county.');
        if (
strlen($username)) < 4){
         
$error[] = urlencode('County names must be at least 4 characters long.');
        }

        
$password_1 = (isset($_POST['password_1'])) trim(? $_POST['password_1']) : '';
        if(empty(
$password_1)){
        
$error[]=urlencode('Please enter password 1.');
        if (
strlen($password_1)) < 6){
        
$error[] = urlencode('Passwords must be at least 6 characters long.');
        }

        
$password_2 = (isset($_POST['password_2'])) trim(? $_POST['password_2']) : '';
        if(empty(
$password_2)){
        
$error[]=urlencode('Please enter password 2.');
        if (
strlen($password_2)) < 6){
        
$error[] = urlencode('Passwords must be at least 6 characters long.');
        }
        
        
$password = ($password_1 == $password_2) ? $password_1 '';
        if (empty(
$error)) { 
            
$sql 'INSERT INTO site_users
                    (email, password, name, username, age, phone, address, county)
                VALUES
                ("' 
mysql_real_escape_string($email$db) . '",
                PASSWORD("' 
mysql_real_escape_string($password$db) . '"), 
                "' 
mysql_real_escape_string($name$db) . '",
                "' 
mysql_real_escape_string($username$db) . '",
                  "' 
mysql_real_escape_string($age$db) . '",
                   "' 
mysql_real_escape_string($phone$db) . '",
                   "' 
mysql_real_escape_string($address$db) . '",
                "' 
mysql_real_escape_string($county$db) . '")';
            
            
mysql_query($sql$db) or die(mysql_error($db));

            
session_start();
            
$_SESSION['user_id'] = mysql_insert_id($db);
            
$_SESSION['access_level'] = 1;
            
$_SESSION['name'] = $name;
            
$_SESSION['username'] = $username;
        
        }else{
        
header('Location:register.php?action=create account' .
              
'&error=' join($errorurlencode('<br/>')));
        }
        
redirect('cms_index.php');
        break; 
The Form
PHP Code:
<table width="400" style="border:1px #0094ff dashed; align="center" cellpadding="30" cellspacing="1" bgcolor="#ffffff">
<tr>
<form method="post" action="cms_transact_user.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  <tr>
  <td colspan="3"><strong><br/>Sign Up</strong></td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  </tr>
  <tr>
   <td><label for="name">Full&nbsp;Name: </label></td>
   <td><input type="text" id="name" name="name" maxlength="100" style="width: 200px;"
     value="<?php echo htmlspecialchars($name); ?>"/></td>
  </tr>
   <tr>
   <td><label for="name">User&nbsp;Name: </label></td>
   <td><input type="text" id="username" name="username" maxlength="100" style="width: 200px;"
     value="<?php echo htmlspecialchars($username); ?>"/></td>
  </tr><tr>
   <td><label for="email">Email&nbsp;Address:</label></td>
   <td><input type="text" id="email" name="email" maxlength="100" style="width: 200px;"
     value="<?php echo htmlspecialchars($email); ?>"/></td>
  </tr>
  
<tr>
   <td><label for="password_1">Password:</label></td>
   <td><input type="password" id="password_1" name="password_1" maxlength="50" style="width: 200px;"/>
   </td>
  </tr><tr>
   <td><label for="password_2">Password&nbsp;(again):</label></td>
   <td><input type="password" id="password_2" name="password_2" maxlength="50" style="width: 200px;"/>
   </td>
  </tr>
  <tr>
   <td><label for="age">Age:</label></td>
   <td><input type="text" id="age" name="age" maxlength="10" style="width: 200px;"/>
   </td>
  </tr>
    <tr>
   <td><label for="phone">Phone:</label></td>
   <td><input type="text" id="phone" name="phone" maxlength="20" style="width: 200px;"/>
   </td>
  </tr>
    <tr>
   <td><label for="address">Address:</label></td>
   <td><input type="text" id="address" name="address" maxlength="50" style="width: 200px;"/>
   </td>
  </tr>
  <tr>
   <td><label for="county">County:</label></td>
   <td><input type="text" id="county" name="county" maxlength="50" style="width: 200px;"/>
   </td>
  </tr>

  
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
   <td>
    <input type="submit" name="action" value="Create Account"/>
   </td>
  </tr>
  

    
   </table>
  </form>
</table>
There shouln't be too much wrong with it, I could just do with some help to sort it out.
Thanks in advance