Jump to content

syntax error, unexpected T_CASE


djlfreak

Recommended Posts

Hi all,

I'm working on a sign up form which I'm trying to validate and I took out the regular expressions to try and test it with just a blank field check and I'm getting the error Unexpected T_CASE on line 182. I can't see where I've gone wrong and I desperately need this to work so if anyone can help I'd be so grateful.

 

  case 'Create Account':
	$name = (isset($_POST['name'])) ? trim($_POST['name']) : '';
	ETC...
        $password_1 = (isset($_POST['password_1'])) ? trim($_POST['password_1']) : '';
        $password_2 = (isset($_POST['password_2'])) ? trim($_POST['password_2']) : '';
        $password = ($password_1 == $password_2) ? $password_1 : '';

	if (isset($_POST['submit']) && $_POST['submit'] == 'Create Account') {

    $errors = array();

    // make sure manditory fields have been entered

if (empty($name)) {
        $errors[] = 'Name cannot be blank.';
    }
etc...
    if (empty($username)) {
        $errors[] = 'Username cannot be blank.';
    }
	// 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 = '';
	}

	mysql_free_result($result);

if (empty($age)) {
        $errors[] = 'Age cannot be blank.';
    }	
ETC....

if (empty($password_2)) {
        $errors[] = 'Password cannot be blank.';
    }

    if (count($errors) > 0) {
        echo '<p><strong style="color:#FF000;">Unable to process your ' . 
            'registration.</strong></p>';
        echo '<p>Please fix the following:</p>';
        echo '<ul>';
        foreach ($errors as $error) {
            echo '<li>' . $error . '</li>';
        }
        echo '</ul>';
    } else {
        // No errors so enter the information into the database.
	 $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) . '"), 
			ETC...
			"' . mysql_real_escape_string($county, $db) . '")';

			$result = 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;

        redirect('cms_index.php');
        break;

The error is coming from the last line of the code above.

 

 

The Form

		
<form method="post" action="cms_transact_user.php">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  <tr><td><label for="name">Full Name: </label></td>
   <td><input type="text" id="name" name="name" maxlength="100" style="width: 200px;"
     value="<?php echo htmlspecialchars($name); ?>"/></td>
  </tr>
  etc...
<tr> <td><input type="submit" name="action" value="Create Account"/>
   </td></tr>
  </table>
  </form>

Link to comment
https://forums.phpfreaks.com/topic/203843-syntax-error-unexpected-t_case/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.