1

I'm trying to create a registration page from a HTML form that validates through to the PHP page (code supplied below), However, when I submit the form, i get the following error:

( ! ) Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in path/user_create.php

Here's the code that enters the input from the form into the database:

<?php
session_start();
require_once __DIR__.'config.php';


if(isset($_POST['submit'])){
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];

$sql = "INSERT INTO users ( username, password, email) VALUES ( :username, :password, :email )";

$query = $dbh->prepare( $sql );
$query->execute( array( ':username'=>$username, ':password'=>$password, ':address'=>$address, ':email'=>$email ) );

$result = $query->execute( array( ':username'=>$username, ':password'=>$password, ':email'=>$email ) );

if ( $result ){
  echo "<p>Your Registration is complete</p>";
} else {
  echo "<p>There was a problem with registration, please try again.</p>";
}
}

?>

Can anyone tell me how to stop this error? Not sure if it an error in the syntax or something else?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
stark
  • 287
  • 4
  • 9
  • 20

1 Answers1

3

The only error I can see is the missing slash. According to the manual:

... This directory name does not have a trailing slash unless it is the root directory.

So you need:

require_once __DIR__.'/config.php';
                      ^ here
jeroen
  • 91,079
  • 21
  • 114
  • 132
  • Nice catch! But it doesn't explain why OP gets an `unexpected require_once` :) – Rizier123 Apr 10 '15 at 12:45
  • require_once will throw an fatal error if the specified file is not in the given path, since in the above line '/' is missed and thats the reason it throws an error... and _DIR_ will give document root path without slash – Vinodkumar SC Apr 10 '15 at 12:48
  • 3
    That's why I think OP doesn't show us the correct file which produces this error OR he doesn't show the real code, which may has some things before `require_once` or he has an [zero-width-space](http://en.wikipedia.org/wiki/Zero-width_space) in the script – Rizier123 Apr 10 '15 at 12:49
  • 2
    @VinodkumarSaravana The warning would be different and it would be a runtime error, not a parse error. – jeroen Apr 10 '15 at 12:50
  • @Rizier123 Yeah, sounds like another place or file with a missing `;` at the end of the previous line or something like that. – jeroen Apr 10 '15 at 12:51
  • 1
    @user1830632 A bit unexpected, but great! – jeroen Apr 10 '15 at 12:52
  • @jeroen Yeah, I did miss that slash after all ;-) *More coffee per favor* – Funk Forty Niner Apr 10 '15 at 12:54
  • @jeroen Grazie mille! – Funk Forty Niner Apr 10 '15 at 12:55
  • @jeroen I would say: `Sack Overflow question parse error: unexpected accept` :) Well it fixed it for OP, so all is fine. (But it's a bit weird because it doesn't match the error which OP got) – Rizier123 Apr 10 '15 at 12:56