Data Not inserted in Database php, mysql
Can't insert data into DB . When i remove user_id then data is inserted. Please check below my code and help me.
function adddata($data)
global $db;
if (is_array($data))
$stmt = $db->prepare('INSERT INTO `pay` (id, payment, status, itemid, time, user_id) VALUES(?, ?, ?, ?, ?, ?');
$userid = 2;
$stmt->bind_param(
'sdssss',
$data['txn_id'],
$data['payment_amount'],
$data['payment_status'],
$data['item_number'],
date('Y-m-d H:i:s'),
$userid
);
$stmt->execute();
$stmt->close();
return $db->insert_id;
return false;
php mysql api mysqli
add a comment |
Can't insert data into DB . When i remove user_id then data is inserted. Please check below my code and help me.
function adddata($data)
global $db;
if (is_array($data))
$stmt = $db->prepare('INSERT INTO `pay` (id, payment, status, itemid, time, user_id) VALUES(?, ?, ?, ?, ?, ?');
$userid = 2;
$stmt->bind_param(
'sdssss',
$data['txn_id'],
$data['payment_amount'],
$data['payment_status'],
$data['item_number'],
date('Y-m-d H:i:s'),
$userid
);
$stmt->execute();
$stmt->close();
return $db->insert_id;
return false;
php mysql api mysqli
3
Think there is a missing)inVALUES(?, ?, ?, ?, ?, ?');
– Nigel Ren
Nov 14 '18 at 20:21
This stands to be a typo-based issue for more than just the missing bracket. The "id" column, is that an string based column or integer?
– Funk Forty Niner
Nov 14 '18 at 20:30
sir this is a string column of my id.
– Arsalan khatri
Nov 14 '18 at 20:32
Is youridvalue always the same? Because if it's a primary key then you wouldn't insert.
– Michael O.
Nov 14 '18 at 20:42
yes got it, thanks nigel Ren. bracket missing in my query. having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute.
– Arsalan khatri
Nov 14 '18 at 20:54
add a comment |
Can't insert data into DB . When i remove user_id then data is inserted. Please check below my code and help me.
function adddata($data)
global $db;
if (is_array($data))
$stmt = $db->prepare('INSERT INTO `pay` (id, payment, status, itemid, time, user_id) VALUES(?, ?, ?, ?, ?, ?');
$userid = 2;
$stmt->bind_param(
'sdssss',
$data['txn_id'],
$data['payment_amount'],
$data['payment_status'],
$data['item_number'],
date('Y-m-d H:i:s'),
$userid
);
$stmt->execute();
$stmt->close();
return $db->insert_id;
return false;
php mysql api mysqli
Can't insert data into DB . When i remove user_id then data is inserted. Please check below my code and help me.
function adddata($data)
global $db;
if (is_array($data))
$stmt = $db->prepare('INSERT INTO `pay` (id, payment, status, itemid, time, user_id) VALUES(?, ?, ?, ?, ?, ?');
$userid = 2;
$stmt->bind_param(
'sdssss',
$data['txn_id'],
$data['payment_amount'],
$data['payment_status'],
$data['item_number'],
date('Y-m-d H:i:s'),
$userid
);
$stmt->execute();
$stmt->close();
return $db->insert_id;
return false;
php mysql api mysqli
php mysql api mysqli
edited Nov 14 '18 at 22:58
Roman Pokrovskij
4,413135184
4,413135184
asked Nov 14 '18 at 20:17
Arsalan khatriArsalan khatri
63
63
3
Think there is a missing)inVALUES(?, ?, ?, ?, ?, ?');
– Nigel Ren
Nov 14 '18 at 20:21
This stands to be a typo-based issue for more than just the missing bracket. The "id" column, is that an string based column or integer?
– Funk Forty Niner
Nov 14 '18 at 20:30
sir this is a string column of my id.
– Arsalan khatri
Nov 14 '18 at 20:32
Is youridvalue always the same? Because if it's a primary key then you wouldn't insert.
– Michael O.
Nov 14 '18 at 20:42
yes got it, thanks nigel Ren. bracket missing in my query. having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute.
– Arsalan khatri
Nov 14 '18 at 20:54
add a comment |
3
Think there is a missing)inVALUES(?, ?, ?, ?, ?, ?');
– Nigel Ren
Nov 14 '18 at 20:21
This stands to be a typo-based issue for more than just the missing bracket. The "id" column, is that an string based column or integer?
– Funk Forty Niner
Nov 14 '18 at 20:30
sir this is a string column of my id.
– Arsalan khatri
Nov 14 '18 at 20:32
Is youridvalue always the same? Because if it's a primary key then you wouldn't insert.
– Michael O.
Nov 14 '18 at 20:42
yes got it, thanks nigel Ren. bracket missing in my query. having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute.
– Arsalan khatri
Nov 14 '18 at 20:54
3
3
Think there is a missing
) in VALUES(?, ?, ?, ?, ?, ?');– Nigel Ren
Nov 14 '18 at 20:21
Think there is a missing
) in VALUES(?, ?, ?, ?, ?, ?');– Nigel Ren
Nov 14 '18 at 20:21
This stands to be a typo-based issue for more than just the missing bracket. The "id" column, is that an string based column or integer?
– Funk Forty Niner
Nov 14 '18 at 20:30
This stands to be a typo-based issue for more than just the missing bracket. The "id" column, is that an string based column or integer?
– Funk Forty Niner
Nov 14 '18 at 20:30
sir this is a string column of my id.
– Arsalan khatri
Nov 14 '18 at 20:32
sir this is a string column of my id.
– Arsalan khatri
Nov 14 '18 at 20:32
Is your
id value always the same? Because if it's a primary key then you wouldn't insert.– Michael O.
Nov 14 '18 at 20:42
Is your
id value always the same? Because if it's a primary key then you wouldn't insert.– Michael O.
Nov 14 '18 at 20:42
yes got it, thanks nigel Ren. bracket missing in my query. having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute.
– Arsalan khatri
Nov 14 '18 at 20:54
yes got it, thanks nigel Ren. bracket missing in my query. having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute.
– Arsalan khatri
Nov 14 '18 at 20:54
add a comment |
1 Answer
1
active
oldest
votes
It's subtle, but your SQL string is missing a closing bracket:
$stmt = $db->prepare('INSERT INTO `pay` (...) VALUES (?, ?, ?, ?, ?, ?)');
Where the VALUES list was not properly closed.
A lot of problems can be detected and resolved by enabling exceptions in mysqli so mistakes aren't easily ignored. This should show up as a SQL error in your logs.
having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute
– Arsalan khatri
Nov 14 '18 at 21:02
"Will not execute" is not sufficiently detailed. If you can be more specific, like the exact error text you're getting, it's worth opening this up as a new question where that problem can be addressed.
– tadman
Nov 14 '18 at 21:37
add a comment |
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%2f53308122%2fdata-not-inserted-in-database-php-mysql%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's subtle, but your SQL string is missing a closing bracket:
$stmt = $db->prepare('INSERT INTO `pay` (...) VALUES (?, ?, ?, ?, ?, ?)');
Where the VALUES list was not properly closed.
A lot of problems can be detected and resolved by enabling exceptions in mysqli so mistakes aren't easily ignored. This should show up as a SQL error in your logs.
having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute
– Arsalan khatri
Nov 14 '18 at 21:02
"Will not execute" is not sufficiently detailed. If you can be more specific, like the exact error text you're getting, it's worth opening this up as a new question where that problem can be addressed.
– tadman
Nov 14 '18 at 21:37
add a comment |
It's subtle, but your SQL string is missing a closing bracket:
$stmt = $db->prepare('INSERT INTO `pay` (...) VALUES (?, ?, ?, ?, ?, ?)');
Where the VALUES list was not properly closed.
A lot of problems can be detected and resolved by enabling exceptions in mysqli so mistakes aren't easily ignored. This should show up as a SQL error in your logs.
having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute
– Arsalan khatri
Nov 14 '18 at 21:02
"Will not execute" is not sufficiently detailed. If you can be more specific, like the exact error text you're getting, it's worth opening this up as a new question where that problem can be addressed.
– tadman
Nov 14 '18 at 21:37
add a comment |
It's subtle, but your SQL string is missing a closing bracket:
$stmt = $db->prepare('INSERT INTO `pay` (...) VALUES (?, ?, ?, ?, ?, ?)');
Where the VALUES list was not properly closed.
A lot of problems can be detected and resolved by enabling exceptions in mysqli so mistakes aren't easily ignored. This should show up as a SQL error in your logs.
It's subtle, but your SQL string is missing a closing bracket:
$stmt = $db->prepare('INSERT INTO `pay` (...) VALUES (?, ?, ?, ?, ?, ?)');
Where the VALUES list was not properly closed.
A lot of problems can be detected and resolved by enabling exceptions in mysqli so mistakes aren't easily ignored. This should show up as a SQL error in your logs.
answered Nov 14 '18 at 20:53
tadmantadman
157k19179209
157k19179209
having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute
– Arsalan khatri
Nov 14 '18 at 21:02
"Will not execute" is not sufficiently detailed. If you can be more specific, like the exact error text you're getting, it's worth opening this up as a new question where that problem can be addressed.
– tadman
Nov 14 '18 at 21:37
add a comment |
having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute
– Arsalan khatri
Nov 14 '18 at 21:02
"Will not execute" is not sufficiently detailed. If you can be more specific, like the exact error text you're getting, it's worth opening this up as a new question where that problem can be addressed.
– tadman
Nov 14 '18 at 21:37
having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute
– Arsalan khatri
Nov 14 '18 at 21:02
having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute
– Arsalan khatri
Nov 14 '18 at 21:02
"Will not execute" is not sufficiently detailed. If you can be more specific, like the exact error text you're getting, it's worth opening this up as a new question where that problem can be addressed.
– tadman
Nov 14 '18 at 21:37
"Will not execute" is not sufficiently detailed. If you can be more specific, like the exact error text you're getting, it's worth opening this up as a new question where that problem can be addressed.
– tadman
Nov 14 '18 at 21:37
add a comment |
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.
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%2f53308122%2fdata-not-inserted-in-database-php-mysql%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
3
Think there is a missing
)inVALUES(?, ?, ?, ?, ?, ?');– Nigel Ren
Nov 14 '18 at 20:21
This stands to be a typo-based issue for more than just the missing bracket. The "id" column, is that an string based column or integer?
– Funk Forty Niner
Nov 14 '18 at 20:30
sir this is a string column of my id.
– Arsalan khatri
Nov 14 '18 at 20:32
Is your
idvalue always the same? Because if it's a primary key then you wouldn't insert.– Michael O.
Nov 14 '18 at 20:42
yes got it, thanks nigel Ren. bracket missing in my query. having also one issue can you please solve ? want to pass $_SESSION[userid]; in to my $userid variable. when i hardcode value in to $userid variable then query run successfully. but when pass $_SESSION[userid] query not execute.
– Arsalan khatri
Nov 14 '18 at 20:54