Several MySQL users in Joomla 1.5 configuration.php - php

In order to solve MySQL 1226 error i follow this recomendation, but it doesn't work.
I'm getting an error:
Parse error: syntax error, unexpected T_VARIABLE in configuration.php on line 38
configuration.php content:
1:<?php
2:class JConfig {
.....
37:public $users = array("root", "boot", "foot");
38:public $user = $users[array_rand($users)];
.....
90:}
91:?>
Please help me fix it.

Problem is solved by adding __construct() function:
var $user = '';
var $users = array("root", "boot", "foot");
public function __construct() {
$this->user = $this->users[mt_rand(0, count($this->users) - 1)];
}

Related

syntax error, unexpected T_OBJECT_OPERATOR? Facebook

I am practicing with facebook PHP api
when i am trying to make a login function
here comes out this warnning
syntax error, unexpected T_OBJECT_OPERATOR in /home/u528851895/public_html/Desktap/facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookResponse.php on line 137
but it's ok when i use mamp localhost
here's line 136~138 in FacebookResponse.php:
public function getGraphObject($type = 'Facebook\GraphObject') {
return (new GraphObject($this->responseData))->cast($type);
}
Upgrade your php version or do something like this
public function getGraphObject($type = 'Facebook\GraphObject') {
$obj = new GraphObject($this->responseData);
return $obj->cast($type);
}

Parse error: syntax error, unexpected T_DNUMBER in /home/a3206525/public_html/easymailer/inc/db_wrapper.php on line 6

I'm quite new on PHP coding and would like to see If it's possible to get help of the code below. Apparently the error is only on line 6.
<?php
class DBWrapper
{
function DBWrapper($server,$db,$user,$pass)
{
$this->Server = $server;
$this->DB = $db;
$this->User = $user;
$this->Password = $pass;
mysql_connect($this->Server, $this->User, $this->password) or
die("Can't connect, please check your settings. Here is the MySQL error: ".mysql_error());
mysql_select_db($this->DB) or
die("Can't select DB, please check your settings. Here is the MySQL error: ".mysql_error());
}
I really hope to receive some help about this.
This:
$this->Server = $mysql3.000webhost.com;
You have no quotes on this "string", so it's being parsed as:
$this->Sever = somevariable concatenate with undefined/illegal constant concatenate with undefined constant
Perhaps
$this->Server = '$mysql3.000webhost.com';
or something?
$this->Server = $#####;
$this->DB = $#####;
$this->User = $######;
$this->Password = $#######;
Hmm, aren't those strings? If so, skip $ and put them into '.
$this->Server = 'mysql3.000webhost.com';
$this->DB = 'a3206525_ezmail';
$this->User = 'a3206525_ezmail';
$this->Password = 'belfegor666';
Also, it's not wise to publish your credentials ;)
And the most important advice, read some more about PHP. It'll really help you.

Parse error: syntax error, unexpected '$_POST' (T_VARIABLE) error and i just cant understand why?

I am trying to write this simple class in php as follows:
<?php
session_start();
require 'db_con.php';
class logg{
private $db;
private $username = $_POST['usr_name'];
private $password = $_POST['usr_pass'];
private $query = "SELECT * FROM user WHERE nick='$username'";
function __construct(){
$this->db = new DB();
}
function loggIn(){
try{
$res = $this->db->fetch($query)
foreach($res as $row) {
$dbusername = $row['nick'];
$dbpassword = $row['pass']; }
if ($username == $dbusername && $password == $dbpassword) {
$_SESSION['username'] = $dbusername;
header('Location: index.php');
} catch (Exception $e){
echo'Wrong login information!'
}
}
}
function loggOut(){
session_destroy();
}
}
?>
but i keep getting the following error:
Parse error: syntax error, unexpected '$_POST' (T_VARIABLE) and i just cant figure out why! Even if i remove theese rows:
private $username = $_POST['usr_name'];
private $password = $_POST['usr_pass'];
i instead get the following error:
( ! ) Parse error: syntax error, unexpected '"' in
im certain the error is a real simple one, but I just can't seem to figure it out..!
Any help appriciated!
Aside from a syntax error on your echo line, the actual problem resulting in this particular error is that you can only initialise class members like that with constants.
Since constants never begin with a $, your initialisations exhibit a syntax error.
You'll have to assign to those members in the class's constructor, instead, just like you do for $db.
You're missing a semi-colon here:
echo'Wrong login information!' // <-- HERE

php Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION on construct

hey guys was hoping you could help me out..
just to let u know in advance, im a relatively new php coder, doing a practice project, and came across this problem and ive spent like an hour of rechecking and googling but just cant figure out whats causing it
error: Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\wamp\www\forum\classes\ClassUser.php on line 7
the segment of the code causing the problem:
include $_SERVER["DOCUMENT_ROOT"]."forum/classes/general.inc";
Class User{
__construct($u,$p){ //this is line 7
$user=$u;
if(strlen($p)>30|| empty($p) || !preg_match('/[^a-zA-Z0-9]/i',$p)){
$password=0;
}
else{
$password=hash_hmac('md5',$p,KEY);
}
}
oh and since im new to php, incase im doing something which i should not be, please to recommend.. thanks in advance.
note:ive removed the php tags since they seemed to be messing with the formatting of this post :/
note2: im also getting another notice
Notice: Use of undefined constant KEY - assumed 'KEY' in C:\wamp\www\forum\classes\general.inc on line 20
but im assuming thats more of a warning than an error... but just adding incase it has something to do with the error
general.inc:
//error definations
define("ERROR_FIELD_EMPTY","Error! All required fields not filled");
define("ERROR_INVALID_SIGNIN","Error! Username/password do not match!");
define("ERROR_GENERAL_INPUT", "Error! Invalid input given");
define("ERROR_SQL_CONNECT","Error! Could not connect to sql database");
//field sizes
define("PASSWORD_LENGTH",12);
define("USERNAME_LENGTH",30);
//sql server details
define("SQL_SERVER_NAME","localhost");
define("SQL_SERVER_USERNAME","root");
define("SQL_SERVER_PASSWORD","");
define("SQL_SERVER_DATABASE","forums");
define(KEY,"key");
function __autoload($className){
require_once($_SERVER["DOCUMENT_ROOT"]."forum/classes/Class$className.php");
}
ClassUser.php
include $_SERVER["DOCUMENT_ROOT"]."forum/classes/general.inc";
Class User{
__construct($u,$p){
$user=$u;
if(strlen($p)>30|| empty($p) || !preg_match('/[^a-zA-Z0-9]/i',$p)){
$password=0;
}
else{
$password=hash_hmac('md5',$p,KEY);
}
}
public function validate(){
if(strlen($user)>30|| empty($user) || preg_match('/[^a-zA-Z0-9]/i',$password==0 )){
throw new Exception(ERROR_GENERAL_INPUT);
}
$user=mysql_real_escape_string($user);
return true;
}
public function insert(){
// this->validate();
$conn= mysqli_connect(SQL_SERVER_NAME,SQL_SERVER_USERNAME,SQL_SERVER_PASSWORD,SQL_SERVER_DATABASE);
if(empty($conn)){
throw new Exception(ERROR_SQL_CONNECT);
}
$query="INSERT into USERS VALUES ($user,$password)";
$conn->query($query);
}
private $user;
private $password;
};
NewUser.php
include $_SERVER["DOCUMENT_ROOT"]."forum/classes/general.inc";
try{
$user = new User($_POST['UserName'],$_POST['Password']);
$user->insert();
}
catch(Exception $Error){
echo $Error->getMessage();
}
Your __construct needs to have the word function in front of it, or better yet public function, in the same way as the other methods in the class (ie validate and insert in your case).
ie you need the following:
public function __construct($u,$p){ //this is line 7
Change the line to:
public function __construct($u, $p) {

Error when trying to declare a variable as a parameter. No problem when i try to declare it inside the function

I have this function:
public static function getOrdini($sort_order = 4)
{
$con = Propel::getConnection();
$sql = "select * from shop_orders LEFT JOIN shop_orders_total
ON
shop_orders.orders_id = shop_orders_total.orders_id
AND
shop_orders_total.sort_order = :sort_order";
$stmt = $con->prepare($sql);
$result = $stmt->execute(array(':sort_order' => $sort_order));
$ordini = self::populateObjects($stmt);
return $ordini;
}
When I call it I get this error:
( ! ) Catchable fatal error: Object of
class Criteria could not be converted
to string in
/home/javier/Aptana_Studio_Workspace/dev_repo/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel/util/DebugPDOStatement.php
on line 99
but if write the function in this way below I don't get any error:
public static function getOrdini()
{
$sort_order = 4;
$con = Propel::getConnection();
...
Any idea?
Regards
Javi
No bug in the above code it is okay. I tried passing value in the static method and it is fine the error is being generated from the other part of your code checking in the class Criteria would help you here is nothing in the posted.
Ask to propel, symfony. here someone is facing the same problem
http://symfonyexperts.com/question/show/id/51

Categories