Nellic17 Posted October 2, 2017 Share Posted October 2, 2017 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!'); } } } ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted October 2, 2017 Share Posted October 2, 2017 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. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted October 3, 2017 Share Posted October 3, 2017 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. http://php.net/manual/en/faq.passwords.php Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 3, 2017 Share Posted October 3, 2017 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) Note: If 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(); 1 Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted October 3, 2017 Share Posted October 3, 2017 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. http://php.net/manual/en/language.types.array.php Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 3, 2017 Share Posted October 3, 2017 Nothing wrong with it but why do more typing then you need to. 7 characters VS 2 characters every time you have it in the app. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted October 3, 2017 Share Posted October 3, 2017 Hmm...I like the more obvious nature of array(). Maybe it's just a matter of getting used to []. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 3, 2017 Share Posted October 3, 2017 I like using array() also. It is much more obvious. As for saving finger steps, how about saving mind steps by not thinking of such simple & unnecessary 'improvements'? Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 3, 2017 Share Posted October 3, 2017 Perhaps you guys would like this then... $v = variable("my_variable"); Now there is no confusion this is a variable. Feel free to do more typing, it's not my time. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted October 4, 2017 Share Posted October 4, 2017 Perhaps you guys would like this then... $v = variable("my_variable"); As long as the following works, I'm on board : $a = variable(array('v1', 'v2')); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.