Jump to content

Recommended Posts

Hello,

I am currently coding a site from scratch. I know i can use templates and everything else but i want the experience. The HTML I've had down for years but it seems PHP is getting a little elusive for me. I'm trying to create a registration form and when i test my site i keep getting parse errors and syntax errors... mainly regarding the use of {} and if/else. Any help would be appreciated. Most of the code is still incomplete, I have to go back and fill in some areas I've left blank for now, but i have commented using // Where the browser is kicking back my errors. 

 

“Any sufficiently advanced technology is indistinguishable from magic” (Arthur C. Clark, 1962) 

 

<?php
$con = Mysqli_connect("'', '', ''");
if (Mysqli_connect_errno()) {
  echo "Failed to connect to DB. Please check your connection info." . Mysqli_connect_errno;
  // Only if there is an error.
}
//Declaring Variable for Registration form
$fname = "";
$lname = "";
$em = "";
$emc = "";
$pass = "";
$passc = "";
$date = "";
$error_array = "";

if (insert($_POST['register_button'])) {
  // To handle the registration form

  // First Name Values
  $fname = strip_tags($_POST['reg_fname']);
  $fname = str_replace(' ', '', $fname);
  $fname = ucfirst(strtolower($fname));

  // Last Name Values
  $lname = strip_tags($_POST['reg_lname']);
  $lname = str_replace(' ', '', $lname);
  $lname = ucfirst(strtolower($lname));

  // Registration Email Values
  $em  = strip_tags($_POST['reg_email']);
  $em = str_replace(' ', '', $em);

  // Confirm Registration Email Values
  $emc = strip_tags($_POST['reg_emailc']);
  $emc = str_replace(' ', '', $emc);

  // Registrsation Password Values
  $pass = strip_tags($_POST['reg_pass']);

  // Registration Password Confirmation Values
  $passc = strip_tags($_POST['reg_passc']);

  // Registration Date Values
  $date = date("m-d-Y");
  
// Here is where the browser keeps kicking back parse errors
  if ($em == $emc) {
  }
  else {
    echo "Email and Confirmation Email must match";

  }
    if (filter_var($em, FILTER_VALIDATE_EMAIL)) {
      $em = filter_var($em, FILTER_VALIDATE_EMAIL)
    }

      else {
      echo "Invlaid Format";
    }




?>

 

Link to comment
https://forums.phpfreaks.com/topic/313498-registration-form-php-code/
Share on other sites

I see two syntax errors

if (insert($_POST['register_button'])) {

The { has no corresponding } later in the code.

    if (filter_var($em, FILTER_VALIDATE_EMAIL)) {
      $em = filter_var($em, FILTER_VALIDATE_EMAIL)
                                                  ^  
    }

      

missing ; at the end of the line

15 minutes ago, Barand said:

I see two syntax errors

if (insert($_POST['register_button'])) {

The { has no corresponding } later in the code.

When i put a } here the syntax error reads "Unexpected } on line blabla"

 

    if (filter_var($em, FILTER_VALIDATE_EMAIL)) {
      $em = filter_var($em, FILTER_VALIDATE_EMAIL)
                                                  ^  
    }

      

missing ; at the end of the line(Thank you for the catch!) You're right!

 

@Barand

 

I went ahead and for the hell of it, added the corrections to the mistakes you noticed. However now i am getting this error.

Fatal error: Uncaught Error: Call to undefined function insert() in register.php:18 Stack trace: #0 {main} thrown in register.php on line 18. 

 

Line 18 references this line here: 

if(insert($_POST['register_button'])) {

  // To handle the registration form
}

On 8/5/2021 at 10:50 AM, Barand said:

Make sure you have defined the function insert(). It's not a PHP function.

(Or did you mean isset() ?)

Why did i not notice this? I am not completely new to PHP. Why in the world did I miss this function? I know better. Grrrrrr! I guess my frustration blinded me. I will fix it now. You are right, insert is not a PHP function. 

 

@Barand

You were correct. This fixed my entire issue. If i had just been paying attention I wouldn't be feeling like an idiot right now! Thank you Dear Sir!

Edited by RedNeckRabbit93

@Barand

That fixed all the issues except for one. 

if (filter_var($em, FILTER_VALIDATE_EMAIL)) {
  $em = filter_var($em, FILTER_VALIDATE_EMAIL);
  
  else {
    echo "Invalid Format";
  }

}

// This code gives me this error: Parse error: syntax error, unexpected 'else' (T_ELSE) in /*****/**/******/htdocs/site/register.php on line 60

If i do it this way:

if (filter_var($em, FILTER_VALIDATE_EMAIL)) {
  $em = filter_var($em, FILTER_VALIDATE_EMAIL);
  }
  else {
    echo "Invalid Format";
  }


//It fixes the rror but the page is constantly returning echo "Invalid Format"; regardless of what is inputted into my form. 

 

Edited by RedNeckRabbit93
Obfuscate Directory names.

Your first one is missing a } before the else. Syntax is

if (condition) {
    do something
}
else {
    do something else
}

It looks like $em  is not valid. Have you tried  var_dump($em) to check what's in there?

 

PS You could just...

if ( ($em = filter_var($em, FILTER_VALIDATE_EMAIL)) === false ) {
   echo "Invalid format"; 
}

 

Edited by Barand
21 hours ago, Barand said:

Your first one is missing a } before the else. Syntax is

if (condition) {
    do something
}
else {
    do something else
}

It looks like $em  is not valid. Have you tried  var_dump($em) to check what's in there?

 

PS You could just...

if ( ($em = filter_var($em, FILTER_VALIDATE_EMAIL)) === false ) {
   echo "Invalid format"; 
}

 

Yeah, it comes out as bool false. Which means I've failed to inform PHP what I'm using $em for

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.