By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,306 Members | 1,621 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,306 IT Pros & Developers. It's quick & easy.

How to fix: Parse error: syntax error, unexpected T_IF

P: 1
Creating a registration form and am getting a parse error on the line in the html form code for email address?!

Any thoughts please.

Expand|Select|Wrap|Line Numbers
  1. // Check for a first name:
  2.     if (empty($_POST['first_name'])) {
  3.     $errors[]='You forgot to enter your first name.';
  4.     } else {
  5.     $fn = trim($_POST['first_name']);
  6.     }
  7.  
  8.     // Check for a last name:
  9.     if (empty($_POST['last_name'])) {
  10.     $errors[]='You forgot to enter your last name.';
  11.     } else {
  12.     $ln = trim($_POST['last_name']);
  13.     }
  14.  
  15.     // Check for an email address:
  16.     if (empty($_POST['email'])) {
  17.     $errors[]='You forgot to enter your email address.';
  18.     } else {
  19.     $e = trim($_POST['email']);
  20.     }
  21.  
  22.     // Check for a password and match against the confirmed password:
  23.     if (!empty($_POST['pass1'])) {
  24.     if ($_POST['pass1'] != $_POST['pass2']) {
  25.     $errors[]='Your password did not match the confirmed password.';
  26.     } else { 
  27.     $p = trim($_POST['pass1']);
  28.     }
  29.     } else {
  30.     $errors[]='You forgot to enter your password.';
  31.     }
  32.  
  33.     if (empty($errors)) { // If everything's OK.
  34.  
  35.     // Register the user in the database...
  36.  
  37.     // Make the query:
  38.     $q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )";
  39.     $r = @mysqli_query ($dbc, $q); // Run the query.
  40.     if ($r) { // If it ran OK.
  41.  
  42.     // Print a message.
  43.     echo '<h1>Welcome</h1>
  44.     <p>You are now registered. Login and challenge!</p>';
  45.  
  46.     } else { // If it did not run OK.
  47.  
  48.     // Public message:
  49.     echo '</h1>System Error</h1>
  50.     <p class="error">You could not be registered due to a system error. We apologise for any inconvenience.</p>';
  51.  
  52.     // Debugging message:
  53.     echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
  54.  
  55.     } // End of if ($r) IF.
  56.  
  57.  
  58.     // Include the footer and quit the script:
  59.     include ('includes/footer.html');
  60.     exit();
  61.  
  62.     } else { // Report the errors.
  63.  
  64.     echo '<h1>Error!</h1>
  65.     <p class="error">The following error(s) occurred:<br />';
  66.     foreach ($errors as $msg) { // Print each error.
  67.     echo " - $msg<br />\n";
  68.     }
  69.     echo '</p><p>Please try again.</p><p><br /></p>';
  70.  
  71.     } // End of if (empty($errors)) IF.
  72.     mysqli_close($dbc); // Close the database connection.
  73.  
  74.     } // End of the main Submit conditional.
  75.     ?>
  76.     <h2><span style="color: #444444; font-weight: normal; letter-spacing: normal; font-size: 19px; line-height: 20px">Registration Form</span><br />
  77. </h2>        
  78. <form action="registration.php" method="post" id="registrationform">        
  79. <p>Registration</p>
  80. <p> <label for="first_name">First Name:</label> <input id="first_name" name="first_name" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" type="text" size="10" maxlength="20" tabindex="1" /></p>
  81. <p> <label for="last_name">Last Name:</label> <input id="last_name" name="last_name" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" type="text" size="10" maxlength="20" tabindex="1" /></p>
  82. <p> <label for="email">Email Address:</label>  <input id="email" name="email" value="<? php if (isset($_POST['email'])) echo $_POST['email']; ?>" type="text" size="20" maxlength="40" tabindex="1" /></p>
  83. <p> <label for="pass1">Password:</label> <input id="pass1" name="pass1" value="" type="password" size="10" maxlength="20" tabindex="1" /></p>
  84. <p> <label for="pass2">Confirm Password:</label> <input id="pass2" name="pass2" value="" type="password" size="10" maxlength="20" tabindex="1" /></p>
  85. <p class="no-border"><input class="button" type="submit" value="Submit" tabindex="5" /></p>
  86. <input type="hidden" name="submitted" value="TRUE" />
  87. </form>
  88.  
Nov 2 '10 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
which line does the error refer to?
Nov 2 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.