Laravel syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING - php

I have upload my files to a new server and error occurres in this line
if(empty($data['customer_id'])) -- Error in thisline
with message syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
the data is comming from
public function store(Request $request)
{
$data = $request->all();
if(empty($data['customer_id']))
$data['customer_id'] = Customer::create($data)->id;
If I change it to $data->customer_id it is not throwing error

Related

Pass checkbox values to database by using codeigniter and that time Error Occured

Parsing Error
Message: syntax error, unexpected ';', expecting ')'
Filename: models/Register_model.php
Line Number: 23
$skills = $this->input->post('skills[]');
$data = array(
'skills' => implode(",", $skills); line nos:23
);
$insert_id=$this->db->insert("regi_user",$data);
return $insert_id;

Codeigniter: Why am i getting this error," unexpected '(', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' "? [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
Parse error: syntax error, unexpected '(', expecting identifier
(T_STRING) or variable (T_VARIABLE) or '{' or '$' in
C:\wamp\www\ghostwriter\application\models\addproject_m.php on line
117
I am trying to create a pagination for my page, so i created a function to fetch the counts of the projects.
function get_projects_count(){
$this->db->select->('p_id')->from('ghost_projects');
$query=$this->db->get();
return $query->num_rows();
}
The above code is in the model.
$this->data['projects'] = $this->addproject_m->ongoingprojects(5,$start);
$this->load->library('pagination');
$config['base_url'] = base_url().'project/search';
$config['total_rows'] = $this->addproject_m->get_projects_count();
$config['per_page'] = 5;
$this->pagination->initialize($config);
$data['pages']=$this->pagination->create_links();
And the above code is from the controller.
Can somebody please help me on this erro i am facing (new to codeigniter).
The problem is in 1 extra '->' that should not be there:
$this->db->select->('p_id')->from('ghost_projects'); //right here
$this->db->select('p_id')->from('ghost_projects'); //this is what it should be
The error tells you that you cannot have '(' after -> which makes sense since you have to ether specify the method name or variable name after ->.
In your query you have and extra -> near select->('p_id').You can also write you select query as
function get_projects_count(){
$this->db->select('p_id');
$this->db->from('ghost_projects'); // there was an extra > before from
$query=$this->db->get();
return $query->num_rows();
}

How to fix "Unexpected T_ENCAPSED_AND_WHITESPACE" error in PHP? [duplicate]

This question already has an answer here:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE) [duplicate]
(1 answer)
Closed 8 years ago.
Here is the error:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\new-training-site\config\info.php on line 4;
Here is line 4:
$link = mysql_query("SELECT * FROM users WHERE id='$_SESSION['MM_Username']' AND password='$_SESSION['MM_PASSWORD']'");
$link = mysql_query("SELECT * FROM users WHERE id='{$_SESSION['MM_Username']}' AND password='{$_SESSION['MM_PASSWORD']}'");
Try this one
$link = mysql_query(sprintf(
"SELECT * FROM users WHERE id='%s' AND password='%s'",
mysql_real_escape_string($_SESSION['MM_Username']),
mysql_real_escape_string($_SESSION['MM_PASSWORD']),
));
It will help you to avoid sql-injection. And please don't use mysql_ functions as it were mentioned in comments

PHP echo href issue

I am trying to add a delete session option in my form, but I cannot get around the following error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /users/bfullilo/acme_dl_sessions.php on line 31
Here is my line 31
echo " Not $_SESSION[\"email\"]?";
I know that I'm not escaping everything I need to, but I've hit a wall. Any help?
It's slightly faster to use single quotes
echo ' Not ' . $_SESSION["email"] . '?';
change to either:
echo " Not $_SESSION[email]?";
or
echo " Not {$_SESSION['email']}?";

Error on Query with $_SESSION Var

$sth7 = $pdo7->prepare("SELECT usr FROM tz_members WHERE id = $_SESSION['id'];");
is giving me this error:
syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
How do I fix this?
Try:
$sth7 = $pdo7->prepare("SELECT usr FROM tz_members WHERE id = " . $_SESSION['id'] . ";");
Here's a link to the exact same problem with a solution.

Categories