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();
}
Related
This question already has answers here:
How to get last inserted row ID from WordPress database?
(7 answers)
Closed 4 years ago.
I want to get last inserted id to update table based on this id. For that I used $wpdb->insert_id for getting the last inserted id. But get this issue
Notice: Undefined property: wpdb::$insertid in D:\wamp\www\wordpress-4.7.1\wordpress\wp-includes\wp-db.php on line 684
this is my code. Someone please help
$parent_id=$template_load_data['id'];
$wpdb->insert( 'wp_rxl_templates', array(
'template_name' => $_POST['template_name_custom'],
'template_content' => $post_content,
'created_date' => current_time( 'mysql' ),
'status' => 'active',
'default_template'=>'false',
'parent_template_id'=>''.$parent_id.'',
));
$result_id = $wpdb->insertid;
$result_data = "select wp_rxl where status ='active' NOT (id = '$result_id')";
You have wrote it as wrong. Check below:
You have to use $wpdb->insert_id instead $wpdb->insertid.
$parent_id=$template_load_data['id'];
$wpdb->insert( 'wp_rxl_templates', array(
'template_name' => $_POST['template_name_custom'],
'template_content' => $post_content,
'created_date' => current_time( 'mysql' ),
'status' => 'active',
'default_template'=>'false',
'parent_template_id'=>''.$parent_id.'',
));
$result_id = $wpdb->insert_id;
$result_data = "select wp_rxl where status ='active' NOT (id = '$result_id')";
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
);
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]
);
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"];
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I use PHP closure function like function() use() on PHP 5.2 version?
I'm trying to run this on a server that's running php 5.2.
function add_post_type($name, $args = array() ) {
add_action('init',function() use($name, $args) {
// execute custom post type code here
});
};
The 2nd line is throwing an unexpected T_FUNCTION error, I suspect its cause of the "use" operator. Can someone help point me as to how I can rewrite this function to run in php 5.2?
See this function:-
/* Add Post Type */
function wpse54191_plugin_init() {
add_post_type('Netherlands', array(
'supports' => array('title', 'editor', 'thumbnail', 'comments')
));
}
add_action('init', 'wpse54191_plugin_init');
/* Add Post Type */
function add_post_type($name, $args = array() ) {
if ( !isset($name) ) return;
$name = strtolower(str_replace(' ', '_', $name));
$args = array_merge(
array(
'label' => 'Members ' . ucwords($name) . '',
'labels' => array('add_new_item' => "Add New $name"),
'singular_name' => $name,
'public' => true,
'supports' => array('title', 'editor', 'comments'),
),
$args
);
register_post_type( $name, $args);
}
This answer seems to provide a good solution for what you're trying to do in PHP 5.2: converting anonymous functions to user-defined functions.
Converting Code with Anonymous functions to PHP 5.2
Good luck! And try and upgrade your PHP version :P