drousiodrawr drousiodrawr - 1 year ago 104
MySQL Question

syntax error, unexpected '.' in PHP OOP

I'm working on a simple project and I'm using PHP Object Oriented. Basically I have a class that contains information about how to get data from MySQL database and show them on a page. This class is called

and goes like this:

class Admin{
private $db,$username,$password,$id,$group,$Datetime,$msg;
public function __construct()
$this->db = new Connection();
$this->db = $this->db->dbConnect();
public function getAdmin($name)
$adm = $this->db->prepare("select * from admins where username=?");
while($row = $adm->fetch())
$this->id = $row['id'];
$this->username = $row['username'];
$this->password = $row['password'];
$this->group = $row['group'];
$this->Datetime = $row['date_joined'];
$this->msg = $row['welcome_message'];
public function getID()
return $this->id;
public function getUsername()
return $this->username;
public function getPassword()
return $this->password;
public function getGroup()
return $this->group;
public function gtDate()
return $this->Datetime;
public function welcomeMessage()
return $this->msg;

Then on another page which is called
,I have included this class file and coded this:

<?php if ($dataSet->welcomeMessage()== 0){
echo "
<li class='dropdown messages-menu'>
<!-- Menu toggle button -->
<a href='#' class='dropdown-toggle' data-toggle='dropdown'>
<i class='fa fa-envelope-o'></i>
<span class='label label-success'>1</span>
<ul class='dropdown-menu'>
<li class='header'>You have one new message</li>
<!-- inner menu: contains the messages -->
<ul class='menu'>
<li><!-- start message -->
<a href='message.php?msg=".$dataSet->msg();."'>
<div class='pull-left'>
<!-- User Image -->
<img src='dist/img/user2-160x160.jpg' class='img-circle' alt='User Image'>
<!-- Message title and timestamp -->
Support Team
<small><i class='fa fa-clock-o'></i>Just now</small>
<!-- The message -->
<p>Welcome to your admin panel</p>
<!-- end message -->
<!-- /.menu -->

But whenever I run it ,I get this error message:

Parse error: syntax error, unexpected '.' on line 15 in dasboard.php

Here's the line 15 of the dasboard file:

<a href='message.php?msg=".$dataSet->msg();."'>

Pretty sure that this must be related to the wrong concatenating and combining a class method within a html tag while I'm echoing out a statement.

So what's the correct way to do this ?

Answer Source

"$dataSet->msg" is not a function but a property, and you need to call it like this.

<a href='message.php?msg=".$dataSet->msg."'> // but wont work as it is private

or use the method call as in the below line

<a href='message.php?msg=".$dataSet->welcomeMessage()."'>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download