Jump to content

Some help here


Nellic17

Recommended Posts

Hi,

please I need someone to tell me what is wrong with this code.

 

It's  displaying Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\data\config.php Am stocked and cant point out whr is wrong.

Am new to php.


<?php
    //I form has been submitted
    if (isset($_POST['register'])){
            $error =array();
            //Check email address
            if (empty(trim($_POST['email']))){
                array_push($error, 'Enter a valid email address.');
            }
            //Check password
            if (empty(trim($_POST['pass']))){
                array_push($error, 'Password field cannot be empty.');
            }elseif(trim($_POST['pass']) <5 || trim($_POST['pass'] >16) ){
                array_push($error, 'Password should be between 5 and 16 characters long.') ;
            }
            //Check if password and confirmed password are the same
            if ( $_POST['pass'] !== $_POST['pass-conf'] ){
                array_push($error, 'Both passwords must correspond.');
            }
            //IF ALL IS CLEAR THEN LET'S BEGIN...
            if (empty($error)){
                //SET PARAMETERS
                $email = htmlentities(striptags(trim($_POST['email'])));
                $pass = htmlentities(striptags(trim($_POST['passs'])));
                //CHECK IF DETAILS ALREADY EXISTS
                $CheckConflict = array();
                $sql = "SELECT uid FROM shop_users WHERE email = ?";
                if ( $stmt = $db->prepare($sql) ){
                    $stmt->bind_param("s", $param_email);
                    $param_email = $email;
                    $stmt->execute;
                    $result = $stmt->get_result;
                    if ( $result->num_rows != 0 ){
                        array_push($CheckConflict, 'Email address has already been used. Please use a different one!');
                    }
                
                
                }

    }
 
 
?>
Link to comment
Share on other sites

You know how indentation works, right? If you start a new block of code surrounded by { and }s then you indent a level. The best thing about indentation is that it's easy to see where each block's { and } are.

 

The good news is that your indentation is correct, which means it should be easy to see each pair of {}s. Take a look for yourself and see if maybe you notice something wrong.

Link to comment
Share on other sites

In addition to the missing curly brace, is striptags() defined in your code? If not, you probably meant to use the following:

http://php.net/manual/en/function.strip-tags.php

 

Note that PHP has a built-in validator for email addresses.

http://php.net/manual/en/filter.examples.validation.php

 

 

At some point, you may notice an issue in the following line:

$pass = htmlentities(striptags(trim($_POST['passs'])));

And in case you're not aware, the PHP manual has some documentation for storing passwords securely.  :happy-04:

http://php.net/manual/en/faq.passwords.php

Link to comment
Share on other sites

Additionally, your script incorrectly depends on the name of a button being submitted in order to work. This can fail completely in certain circumstances. You need to check the server REQUEST METHOD.

if ($_SERVER['REQUEST_METHOD'] == 'POST')

Instead of multiple trim calls, just trim the entire post array at once.

 

Instead of using array_push for the errors just do like so:

 

$error[] = 'Password field cannot be empty.';

 

Per the manual: (http://php.net/manual/en/function.array-push.php)

 

NoteIf you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function.

 

Use the current array syntax. Change $error =array();  

TO

$error = [];// Since 5.4.x

 

Same thing with $CheckConflict = array();

  • Great Answer 1
Link to comment
Share on other sites

Use the current array syntax. Change $error =array();  

TO

$error = [];// Since 5.4.x

 

Is something wrong with array()? The manual mentions that 5.4 added the option for short array syntax. Based on a quick scan, I didn't see anything to suggest that array() is being phased out. Most of the examples in the manual still use the full array syntax.  :confused:

http://php.net/manual/en/language.types.array.php

Link to comment
Share on other sites

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.