Unexpected '=>' (T_DOUBLE_ARROW) [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I am getting the following error and I just cant find the solution to the problem. Might be anyone be able to help me?
DB::table('videos')->insert(
['video_id' => $videos[$i]->title],
['url'] => $videos[$i]->url],
['default_thumb'] => $videos[$i]->default_thumb],
['thumb'] => $videos[$i]->thumb],
['publish_date'] => $videos[$i]->publish_date],
['tags'] => $videos[$i]->tags]
);
The error message is:
FatalErrorException in VideoController.php line 33:
syntax error, unexpected '=>' (T_DOUBLE_ARROW)

This is correct syntax for insert() method:
DB::table('videos')->insert([
'video_id' => $videos[$i]->title,
'url' => $videos[$i]->url,
'default_thumb' => $videos[$i]->default_thumb,
'thumb' => $videos[$i]->thumb,
'publish_date' => $videos[$i]->publish_date,
'tags' => $videos[$i]->tags
]);

Hope it will solve your problem
DB::table('videos')->insert(
['video_id' => $videos[$i]->title,
'url' => $videos[$i]->url,
'default_thumb' => $videos[$i]->default_thumb,
'thumb' => $videos[$i]->thumb,
'publish_date' => $videos[$i]->publish_date,
'tags' => $videos[$i]->tags]
);

Related

Unable to access an array index in a PHP Query [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
Please I need help identifying the problem with my query here:
So this is my hard-coded data because I am trying to test my PHP script on its own with out the android application that usually sends data to it.
I have this array of hardcoded data.
$register_data = array(
'username' => 'david',
'password' => 'david',
'first_name' => 'david',
'last_name' => 'david',
'email' => 'david#yahoo.com'
);
This is my problematic query:
"SELECT * FROM `user_info` WHERE `email` = '$register_data['email']' OR `username` = '$register_data['username']'";
And this is the error i received:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home1/ifedavid/public_html/androidconnect/register.php
Please is there something I'm doing wrong? Thanks for the help in advance.
$register_data = array(
'username' => 'david',
'password' => 'david',
'first_name' => 'david',
'last_name' => 'david',
'email' => 'david#yahoo.com'
);
$query = "SELECT * FROM 'user_info' WHERE 'email' = '".$register_data['email']."' OR 'username' = '".$register_data['username']."'";
Then execute the query with the var $query
Hope it helps

PHP return array | Parse error: syntax error, unexpected '[' in [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I am currently building a response class with PHP to communicate with my backend API if everything went alright. This is the class:
public static function Success($data = null)
{
if (!$data) {
return [
'result' => true
];
} else {
return [
'result' => true,
'data' => $data
];
}
}
But when someone tries to install the plugin on a website it gives the error:
Parse error: syntax error, unexpected '[' in filename on line 13,
Line 13 is where the first bracket [ starts at the first return.
Does anyone know why I get this error? I think it has something to do with the version of PHP or Wordpress.
use
return array(
'result' => true
);

PHP syntax error when using wpdb update? [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I'm not too good with PHP, so I'm having trouble with some code that is supposed to update the wp_posts table. The problem is that when I try to save it, WP deactivates the plugin saying there's a syntax error in the following bit of code:
global $wpdb;
$dbresult = $wpdb->update($wpdb->post, ['post_title' => 'Test Title', 'post_content' => 'Test Content', 'group_access' => $group_access, 'tag_list' => $tag_list], ['ID' => 12095])) :
if (false === $dbresult) {
echo 'An error occurred wile updating...');$errors = $post_id->get_error_messages();
}
I believe it would work if I could figure out what the syntax error was.
There were multiple errors. It should be fixed now.
global $wpdb;
$dbresult = $wpdb->update($wpdb->post, ['post_title' => 'Test Title', 'post_content' => 'Test Content', 'group_access' => $group_access, 'tag_list' => $tag_list], ['ID' => 12095]); // <- One ) to much, : but needed ;
if (false === $dbresult) {
echo ('An error occurred while updating...'); // <- Missing (
$errors = $post_id->get_error_messages();
}

PHP - cannot create array [duplicate]

This question already has an answer here:
Parse error: syntax error, unexpected '[' with php 5.3 [duplicate]
(1 answer)
Closed 8 years ago.
I downloaded and installed Ampps and now I'm using PHP version 5.3.28. When I try to create array i.e.
$foo = ['bar'];
or
$foo = [];
or
$data = [
'ts' => time(),
'ip' => $_SERVER['REMOTE_ADDR'],
'user_id' => #$auth->id,
'method' => $_SERVER['REQUEST_METHOD'],
'uri' => $_SERVER['SCRIPT_NAME'],
'data' => json_encode([
'get' => $_GET,
'post' => $post,
]),
];
etc. I always got error "Parse error: syntax error, unexpected '[' in ...". I didn't change anything. Where is problem and how can I fix it?
Using the syntax [] requires PHP 5.5.0 5.4 and higher, earlier versions have to define arrays as:
$array = array( /* data */);
So, if you wish to use the syntax as exampled. then plan an upgrade to 5.5, otherwise use the alternative method to define an array -- Array Documentation
Try something more explicit like this:
$dataTest = array
(
"ts" => time(),
"ip" => 7
);
echo $dataTest["ts"];
echo $dataTest["ip"];

Unexpected start of array [ [duplicate]

This question already has answers here:
Unexpected bracket '[' - PHP [duplicate]
(3 answers)
PHP 5.4 vs 5.3 app errors
(3 answers)
Closed 9 years ago.
I keep getting this error
syntax error, unexpected '['
it is in the line 1 of the following code snippet:
Route.php
Route::get('api/test/{input}', [
'before' => 'checkauth',
"as" => "test",
"uses" => "TestController#show"
]);
what is wrong?
Change your array notation.
Route::get('api/test/{input}', array(
'before' => 'checkauth',
"as" => "test",
"uses" => "TestController#show"
));
As Michael Berkowski says, the use of the array notation with [ requires PHP 5.4+
From the Php array documentation
As of PHP 5.4 you can also use the short array syntax, which replaces array() with [].
You should use the array(); notation:
Route::get('api/test/{input}', array(
'before' => 'checkauth',
"as" => "test",
"uses" => "TestController#show"
));

Categories