This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
How to get the date from database and echo on PHP page?
$query = $pdo->prepare('SELECT * FROM shop WHERE shopname=:shopname');
$query->bindParam(':shopname', $shopname, PDO::PARAM_STR);
$query->execute();
$result = $query->fetchAll(PDO::FETCH_ASSOC);
echo "$result['shopid']";
This gives me the following error:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),
expecting identifier (T_STRING) or variable (T_VARIABLE) or number
(T_NUM_STRING)
echo "$result['shopid']";
This line is incorrect
echo $result["shopid"];
// OR
echo "{$result['shopid']}";
remove the double quotes, change
echo "$result['shopid']";
with
echo $result['shopid'];
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I'm adding [] this symbol within an execute() in PDO, and it returns error.
I'm working in WAMP5
$sqlStatement="
SELECT *
FROM $table_results
WHERE title = ? AND id_category = ?
";
$stmt = $bdConection->prepare($sqlStatement);
$stmt->execute([$title, $id_category]);
echo $stmt->rowCount();
It works well if I delete WHERE title = ? AND id_category = ? and [$title, $id_category] bur returns more results, instead of adding those ... then
IT RETURNS:
Parse error: syntax error, unexpected '[', expecting ')' in
I can reproduce this error with PHP 5.2. Documentation about PHP array's syntax states:
... As of PHP 5.4 you can also use the short array syntax, which
replaces array() with []. ...
What you can do in your case is to define an array using array():
<?php
$sqlStatement = "
SELECT *
FROM $table_results
WHERE title = ? AND id_category = ?
";
...
$stmt = $bdConection->prepare($sqlStatement);
$stmt->execute(array($title, $id_category));
echo $stmt->rowCount();
...
?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Hello, I'm very new to PHP and im getting this error...:
Parse error: syntax error, unexpected ''arak''
(T_CONSTANT_ENCAPSED_STRING) in /testSQL.php on line 6
...for this line:
$query = UPDATE 'arak' SET `ara` = '$ar1' Limit 0,1;
A little help would be appriciated :)
You have to quote the string by ", protect the table name by ` and protect value with '
$query = "UPDATE `arak` SET `ara` = '$ar1' Limit 0,1";
Be careful, $ar1 must be protected. For example, if $ar1 = '33\'33', you could have problem.
$ar1 = addslashes($ar1);
$query = "UPDATE `arak` SET `ara` = '$ar1' Limit 0,1";
Addslashes is a first step to prevent SQL Injection, but it is not enough as you can read it
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I am trying to assign the contents of a 2D array to a string in PHP.
$sql="SELECT Order_Code FROM Order WHERE CUST_CODE = '$output['username']';";
I know the problem exists in how I'm writing the $output variable assignment.
The following line of code outputs the correct data from the variable:
echo $output['username'];
The following error is being thrown:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
Parameters surrouned by curly brackets will work well in your case. Here is what i mean. {$array['key']}
And for your example:
$sql="SELECT Order_Code FROM Order WHERE CUST_CODE = '{$output['username']}';";
You need to concatenate this string as the multiple single quotes from accessing the array element are mixing up the string.
$sql="SELECT Order_Code FROM Order WHERE CUST_CODE = '" . $output['username'] ."';";
Try this:
$sql="SELECT Order_Code FROM Order WHERE CUST_CODE = '".$output['username']."'";
You can also try this:
$user_name = $output['username'];
$sql = "SELECT Order_Code FROM Order WHERE CUST_CODE = $user_name";
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();
}
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