【发布时间】:2014-02-07 13:23:33
【问题描述】:
我收到这样的错误
解析错误,预计第 4 行出现“T_FUNCTION”
但是当我不使用类时,这些代码可以正常工作。在我没有在 php 代码中使用类之前。我只是写没有类的php代码。现在,我想在我的 php 代码中使用类,所以我实现了一些代码。但这给我带来了上述错误。我在哪里犯了错误? (我以为我在类函数中犯了错误)。
config.php
<?php
class Configuration
{
private $user = "root";
private $password = "password";
public $conn;
public static function connect()
{
if(self::$instance = null)
{
try
{
$conn = new PDO('mysql:host=localhost;dbname=database_table', $user, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
'Database Connection Error' .$e->getMessage();
}
}
return
}
}
?>
post.php
<?php
class StoreDatas
{
include_once('config.php');
if($_POST["register"] == "alldetails")
{
private $r_uname = trim($_POST["uname"]);
private $r_email = trim($_POST["email"]);
//some codes
//some codes
//some codes
// name validation
if(!preg_match("/^[a-zA-Z ]+$/", $r_uname))
{
echo '<b>Name</b> - Name must be from letters and spaces only';
die();
}
// email validation
if(!preg_match("/^[a-zA-Z]\w+(\.\w+)*\@\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]{2,4}$/", $r_email) )
{
echo '<b>Email</b> - Email must comply with this mask: chars(.chars)@chars(.chars).chars(2-4)';
die();
}
//some codes
//some codes
//some codes
function InsertDatas
{
try
{
$stmt = Connection::connect()->prepare("INSERT INTO user_registration ( Name, EmailID, MobileNumber, Password, ReEnterPassword, UserProfileCreatedOn ) VALUES ( ?, ?, ?, ?, ?, NOW() )");
$conn->errorInfo();
$stmt->bindParam('1', $r_uname, PDO::PARAM_STR);
$stmt->bindParam('2', $r_email, PDO::PARAM_STR);
$stmt->bindParam('3', $r_mobile, PDO::PARAM_STR);
$stmt->bindParam('4', $r_password, PDO::PARAM_STR);
$stmt->bindParam('5', $r_reenterpassword, PDO::PARAM_STR);
$stmt->execute();
echo 'Registered Succesfully. You can login now';
echo '<script type="text/JavaScript">$("#registrationform")[0].reset();</script>';
}
catch(PDOException $e)
{
echo 'Failed to insert. Contact your admin' . $e->getMessage();
}
}
}
}
?>
【问题讨论】: