WordPress database error: [Column count doesn't match value count at row 1]
I have a table that looks like this. They all have default 0 value for some reason:
In wordpress I'm inserting new value of score into a table like so:
$scoree = $_POST['whatever'];
global $wpdb;
$table = 'username';
$save = $wpdb->insert($table, $scoree);
wp_send_json(['save' => $save, '$_POST' => $_POST ]);
}
But this gives me an error when alerting AJAX response in javascript file:
Got this from the server: WordPress database error: [Column count doesn't match value count at row 1]
{"save":false,"$_POST":{"action":"my_action","whatever":"9"}}INSERT INTO
username
(``) VALUES ()
My AJAX in JS file:
var data = {
'action': 'my_action',
'whatever' : user1.currentScore
}
jQuery.post(my_ajax_object.ajax_url, data, function(response) {
alert('Got this from the server: ' + response);
});
}
Any ideas why is this hapenning?
php mysql ajax wordpress
add a comment |
I have a table that looks like this. They all have default 0 value for some reason:
In wordpress I'm inserting new value of score into a table like so:
$scoree = $_POST['whatever'];
global $wpdb;
$table = 'username';
$save = $wpdb->insert($table, $scoree);
wp_send_json(['save' => $save, '$_POST' => $_POST ]);
}
But this gives me an error when alerting AJAX response in javascript file:
Got this from the server: WordPress database error: [Column count doesn't match value count at row 1]
{"save":false,"$_POST":{"action":"my_action","whatever":"9"}}INSERT INTO
username
(``) VALUES ()
My AJAX in JS file:
var data = {
'action': 'my_action',
'whatever' : user1.currentScore
}
jQuery.post(my_ajax_object.ajax_url, data, function(response) {
alert('Got this from the server: ' + response);
});
}
Any ideas why is this hapenning?
php mysql ajax wordpress
wpdb::insert says it should be a key pair, developer.wordpress.org/reference/classes/wpdb/insert it says it right there, just follow the formatarray(key => pair, another key => another pair)
– Ghost
Nov 14 '18 at 1:23
What is a key? There is only $scoree and thats it. I haveno key value pairs
– Limpuls
Nov 14 '18 at 1:34
@Ghost Okay, I understood what you said and fixed it. Working now. But I'm still having 0 value to score column by default, and when I save a new one, each username has two values, the 0 default one and a new one just added. How can I fix this? I don't need that 0 by default, just one value newly added
– Limpuls
Nov 14 '18 at 1:55
just debug whatever the value you're getting. if the insertion is now working, then examine the origin of the value, track it from the start until it reaches in the actual insertion code, useconsole.log
,echo
,var_dump
accordingly.array('name' => 'stan lee', 'score' => $score variable name)
like so
– Ghost
Nov 14 '18 at 3:31
add a comment |
I have a table that looks like this. They all have default 0 value for some reason:
In wordpress I'm inserting new value of score into a table like so:
$scoree = $_POST['whatever'];
global $wpdb;
$table = 'username';
$save = $wpdb->insert($table, $scoree);
wp_send_json(['save' => $save, '$_POST' => $_POST ]);
}
But this gives me an error when alerting AJAX response in javascript file:
Got this from the server: WordPress database error: [Column count doesn't match value count at row 1]
{"save":false,"$_POST":{"action":"my_action","whatever":"9"}}INSERT INTO
username
(``) VALUES ()
My AJAX in JS file:
var data = {
'action': 'my_action',
'whatever' : user1.currentScore
}
jQuery.post(my_ajax_object.ajax_url, data, function(response) {
alert('Got this from the server: ' + response);
});
}
Any ideas why is this hapenning?
php mysql ajax wordpress
I have a table that looks like this. They all have default 0 value for some reason:
In wordpress I'm inserting new value of score into a table like so:
$scoree = $_POST['whatever'];
global $wpdb;
$table = 'username';
$save = $wpdb->insert($table, $scoree);
wp_send_json(['save' => $save, '$_POST' => $_POST ]);
}
But this gives me an error when alerting AJAX response in javascript file:
Got this from the server: WordPress database error: [Column count doesn't match value count at row 1]
{"save":false,"$_POST":{"action":"my_action","whatever":"9"}}INSERT INTO
username
(``) VALUES ()
My AJAX in JS file:
var data = {
'action': 'my_action',
'whatever' : user1.currentScore
}
jQuery.post(my_ajax_object.ajax_url, data, function(response) {
alert('Got this from the server: ' + response);
});
}
Any ideas why is this hapenning?
php mysql ajax wordpress
php mysql ajax wordpress
edited Nov 14 '18 at 1:48
Shadow
25.6k92743
25.6k92743
asked Nov 14 '18 at 1:14
Limpuls
337110
337110
wpdb::insert says it should be a key pair, developer.wordpress.org/reference/classes/wpdb/insert it says it right there, just follow the formatarray(key => pair, another key => another pair)
– Ghost
Nov 14 '18 at 1:23
What is a key? There is only $scoree and thats it. I haveno key value pairs
– Limpuls
Nov 14 '18 at 1:34
@Ghost Okay, I understood what you said and fixed it. Working now. But I'm still having 0 value to score column by default, and when I save a new one, each username has two values, the 0 default one and a new one just added. How can I fix this? I don't need that 0 by default, just one value newly added
– Limpuls
Nov 14 '18 at 1:55
just debug whatever the value you're getting. if the insertion is now working, then examine the origin of the value, track it from the start until it reaches in the actual insertion code, useconsole.log
,echo
,var_dump
accordingly.array('name' => 'stan lee', 'score' => $score variable name)
like so
– Ghost
Nov 14 '18 at 3:31
add a comment |
wpdb::insert says it should be a key pair, developer.wordpress.org/reference/classes/wpdb/insert it says it right there, just follow the formatarray(key => pair, another key => another pair)
– Ghost
Nov 14 '18 at 1:23
What is a key? There is only $scoree and thats it. I haveno key value pairs
– Limpuls
Nov 14 '18 at 1:34
@Ghost Okay, I understood what you said and fixed it. Working now. But I'm still having 0 value to score column by default, and when I save a new one, each username has two values, the 0 default one and a new one just added. How can I fix this? I don't need that 0 by default, just one value newly added
– Limpuls
Nov 14 '18 at 1:55
just debug whatever the value you're getting. if the insertion is now working, then examine the origin of the value, track it from the start until it reaches in the actual insertion code, useconsole.log
,echo
,var_dump
accordingly.array('name' => 'stan lee', 'score' => $score variable name)
like so
– Ghost
Nov 14 '18 at 3:31
wpdb::insert says it should be a key pair, developer.wordpress.org/reference/classes/wpdb/insert it says it right there, just follow the format
array(key => pair, another key => another pair)
– Ghost
Nov 14 '18 at 1:23
wpdb::insert says it should be a key pair, developer.wordpress.org/reference/classes/wpdb/insert it says it right there, just follow the format
array(key => pair, another key => another pair)
– Ghost
Nov 14 '18 at 1:23
What is a key? There is only $scoree and thats it. I haveno key value pairs
– Limpuls
Nov 14 '18 at 1:34
What is a key? There is only $scoree and thats it. I haveno key value pairs
– Limpuls
Nov 14 '18 at 1:34
@Ghost Okay, I understood what you said and fixed it. Working now. But I'm still having 0 value to score column by default, and when I save a new one, each username has two values, the 0 default one and a new one just added. How can I fix this? I don't need that 0 by default, just one value newly added
– Limpuls
Nov 14 '18 at 1:55
@Ghost Okay, I understood what you said and fixed it. Working now. But I'm still having 0 value to score column by default, and when I save a new one, each username has two values, the 0 default one and a new one just added. How can I fix this? I don't need that 0 by default, just one value newly added
– Limpuls
Nov 14 '18 at 1:55
just debug whatever the value you're getting. if the insertion is now working, then examine the origin of the value, track it from the start until it reaches in the actual insertion code, use
console.log
, echo
, var_dump
accordingly. array('name' => 'stan lee', 'score' => $score variable name)
like so– Ghost
Nov 14 '18 at 3:31
just debug whatever the value you're getting. if the insertion is now working, then examine the origin of the value, track it from the start until it reaches in the actual insertion code, use
console.log
, echo
, var_dump
accordingly. array('name' => 'stan lee', 'score' => $score variable name)
like so– Ghost
Nov 14 '18 at 3:31
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291797%2fwordpress-database-error-column-count-doesnt-match-value-count-at-row-1%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291797%2fwordpress-database-error-column-count-doesnt-match-value-count-at-row-1%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
wpdb::insert says it should be a key pair, developer.wordpress.org/reference/classes/wpdb/insert it says it right there, just follow the format
array(key => pair, another key => another pair)
– Ghost
Nov 14 '18 at 1:23
What is a key? There is only $scoree and thats it. I haveno key value pairs
– Limpuls
Nov 14 '18 at 1:34
@Ghost Okay, I understood what you said and fixed it. Working now. But I'm still having 0 value to score column by default, and when I save a new one, each username has two values, the 0 default one and a new one just added. How can I fix this? I don't need that 0 by default, just one value newly added
– Limpuls
Nov 14 '18 at 1:55
just debug whatever the value you're getting. if the insertion is now working, then examine the origin of the value, track it from the start until it reaches in the actual insertion code, use
console.log
,echo
,var_dump
accordingly.array('name' => 'stan lee', 'score' => $score variable name)
like so– Ghost
Nov 14 '18 at 3:31