I'm getting the error like this
parse error, expecting 'T_FUNCTION' on line 4
But this codes works fine when i'm not using classes. Before i didn't use classes in php code. I just write php codes without classes. Now, i want to use classes in my php code so, i've implemented some codes. But it throws me an above error. Where i made mistake here? (i thought i've made mistakes in class function).
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();
}
}
}
}
?>