简体   繁体   中英

PHP: sytax error unexpected 'require_once' on registration page

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM