only can insert first and second value other value cannot insert in database. how to solve this?
<?php
require_once "config.php";
if(isset($_POST['save'])){
$values = array();
for($i=0 ; $i <count($_POST['working']); $i++) {
$values = '("' . $_POST['working']['day'][$i] . '","' .
$_POST['working']['status'][$i] . '")'; }
$sql4 = "INSERT INTO working_day(day,status) VALUES " . implode(',',
$values);
$result4=mysqli_query($connection,$sql4);}
?>
<form id="sendform" method="post" action="">
<input type="text" value="Monday" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="Tuesday" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="w" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="T" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="F" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="S" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="S" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="submit" value="Send" name="save" />
</form>
**why this code only can insert first day&status and second day&status into the database ? The for loop count[i] cannot count another value. how to solve this problem? **
php mysql
add a comment |
<?php
require_once "config.php";
if(isset($_POST['save'])){
$values = array();
for($i=0 ; $i <count($_POST['working']); $i++) {
$values = '("' . $_POST['working']['day'][$i] . '","' .
$_POST['working']['status'][$i] . '")'; }
$sql4 = "INSERT INTO working_day(day,status) VALUES " . implode(',',
$values);
$result4=mysqli_query($connection,$sql4);}
?>
<form id="sendform" method="post" action="">
<input type="text" value="Monday" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="Tuesday" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="w" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="T" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="F" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="S" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="S" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="submit" value="Send" name="save" />
</form>
**why this code only can insert first day&status and second day&status into the database ? The for loop count[i] cannot count another value. how to solve this problem? **
php mysql
What does error reporting tell you? What are the values being passed in? What is the query that is executed? Hard to tell as is. Also you are open to SQL injections. Use the prepared statements and parameterize the query.
– user3783243
Nov 26 '18 at 5:26
no any error message. when i submit the form only can get array[0] and array[1] value insert to database other cannot get
– Benjamin Y
Nov 26 '18 at 5:33
Use themysqli
error reporting function. It sounds like you are not accessing the right level. I would doday
andstatus
rather than the multilevel arrays. Rather than just executing your query. Output it as it is generated and see where you're going wrong. No point in execution the incorrect query. Comment out the execution.
– user3783243
Nov 26 '18 at 5:37
add a comment |
<?php
require_once "config.php";
if(isset($_POST['save'])){
$values = array();
for($i=0 ; $i <count($_POST['working']); $i++) {
$values = '("' . $_POST['working']['day'][$i] . '","' .
$_POST['working']['status'][$i] . '")'; }
$sql4 = "INSERT INTO working_day(day,status) VALUES " . implode(',',
$values);
$result4=mysqli_query($connection,$sql4);}
?>
<form id="sendform" method="post" action="">
<input type="text" value="Monday" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="Tuesday" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="w" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="T" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="F" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="S" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="S" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="submit" value="Send" name="save" />
</form>
**why this code only can insert first day&status and second day&status into the database ? The for loop count[i] cannot count another value. how to solve this problem? **
php mysql
<?php
require_once "config.php";
if(isset($_POST['save'])){
$values = array();
for($i=0 ; $i <count($_POST['working']); $i++) {
$values = '("' . $_POST['working']['day'][$i] . '","' .
$_POST['working']['status'][$i] . '")'; }
$sql4 = "INSERT INTO working_day(day,status) VALUES " . implode(',',
$values);
$result4=mysqli_query($connection,$sql4);}
?>
<form id="sendform" method="post" action="">
<input type="text" value="Monday" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="Tuesday" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="w" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="T" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="F" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="S" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="text" value="S" id="day" name="working[day]" readonly />
<input type="text" value="" id="status" name="working[status]" />
<input type="submit" value="Send" name="save" />
</form>
**why this code only can insert first day&status and second day&status into the database ? The for loop count[i] cannot count another value. how to solve this problem? **
php mysql
php mysql
edited Nov 26 '18 at 5:29
Benjamin Y
asked Nov 26 '18 at 5:24
Benjamin YBenjamin Y
163
163
What does error reporting tell you? What are the values being passed in? What is the query that is executed? Hard to tell as is. Also you are open to SQL injections. Use the prepared statements and parameterize the query.
– user3783243
Nov 26 '18 at 5:26
no any error message. when i submit the form only can get array[0] and array[1] value insert to database other cannot get
– Benjamin Y
Nov 26 '18 at 5:33
Use themysqli
error reporting function. It sounds like you are not accessing the right level. I would doday
andstatus
rather than the multilevel arrays. Rather than just executing your query. Output it as it is generated and see where you're going wrong. No point in execution the incorrect query. Comment out the execution.
– user3783243
Nov 26 '18 at 5:37
add a comment |
What does error reporting tell you? What are the values being passed in? What is the query that is executed? Hard to tell as is. Also you are open to SQL injections. Use the prepared statements and parameterize the query.
– user3783243
Nov 26 '18 at 5:26
no any error message. when i submit the form only can get array[0] and array[1] value insert to database other cannot get
– Benjamin Y
Nov 26 '18 at 5:33
Use themysqli
error reporting function. It sounds like you are not accessing the right level. I would doday
andstatus
rather than the multilevel arrays. Rather than just executing your query. Output it as it is generated and see where you're going wrong. No point in execution the incorrect query. Comment out the execution.
– user3783243
Nov 26 '18 at 5:37
What does error reporting tell you? What are the values being passed in? What is the query that is executed? Hard to tell as is. Also you are open to SQL injections. Use the prepared statements and parameterize the query.
– user3783243
Nov 26 '18 at 5:26
What does error reporting tell you? What are the values being passed in? What is the query that is executed? Hard to tell as is. Also you are open to SQL injections. Use the prepared statements and parameterize the query.
– user3783243
Nov 26 '18 at 5:26
no any error message. when i submit the form only can get array[0] and array[1] value insert to database other cannot get
– Benjamin Y
Nov 26 '18 at 5:33
no any error message. when i submit the form only can get array[0] and array[1] value insert to database other cannot get
– Benjamin Y
Nov 26 '18 at 5:33
Use the
mysqli
error reporting function. It sounds like you are not accessing the right level. I would do day
and status
rather than the multilevel arrays. Rather than just executing your query. Output it as it is generated and see where you're going wrong. No point in execution the incorrect query. Comment out the execution.– user3783243
Nov 26 '18 at 5:37
Use the
mysqli
error reporting function. It sounds like you are not accessing the right level. I would do day
and status
rather than the multilevel arrays. Rather than just executing your query. Output it as it is generated and see where you're going wrong. No point in execution the incorrect query. Comment out the execution.– user3783243
Nov 26 '18 at 5:37
add a comment |
1 Answer
1
active
oldest
votes
Correct way is given below :-
<?php
require_once "config.php";
if(isset($_POST['save'])){
$values = array();
for($i=0 ; $i <count($_POST['working']['day']); $i++) {
$values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['status'][$i] . '")';
}
$sql4 = "INSERT INTO working_day(day,status) VALUES " . implode(',', $values);
$result4=mysqli_query($connection,$sql4);
}
if insert more than two different value also like this?
– Benjamin Y
Nov 26 '18 at 5:50
depend on the situation. i am not understanding your case clearly. please explain more or show me the code.
– Parvej Alam
Nov 26 '18 at 6:14
like this $values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['start_time'][$i] . '","' . $_POST['working']['end_time'][$i] . '","' . $_POST['working']['status'][$i] . '")';
– Benjamin Y
Nov 27 '18 at 20:45
yes we can insert as many as we want to add.
– Parvej Alam
Nov 28 '18 at 5:22
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%2f53475150%2fonly-can-insert-first-and-second-value-other-value-cannot-insert-in-database-ho%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
Correct way is given below :-
<?php
require_once "config.php";
if(isset($_POST['save'])){
$values = array();
for($i=0 ; $i <count($_POST['working']['day']); $i++) {
$values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['status'][$i] . '")';
}
$sql4 = "INSERT INTO working_day(day,status) VALUES " . implode(',', $values);
$result4=mysqli_query($connection,$sql4);
}
if insert more than two different value also like this?
– Benjamin Y
Nov 26 '18 at 5:50
depend on the situation. i am not understanding your case clearly. please explain more or show me the code.
– Parvej Alam
Nov 26 '18 at 6:14
like this $values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['start_time'][$i] . '","' . $_POST['working']['end_time'][$i] . '","' . $_POST['working']['status'][$i] . '")';
– Benjamin Y
Nov 27 '18 at 20:45
yes we can insert as many as we want to add.
– Parvej Alam
Nov 28 '18 at 5:22
add a comment |
Correct way is given below :-
<?php
require_once "config.php";
if(isset($_POST['save'])){
$values = array();
for($i=0 ; $i <count($_POST['working']['day']); $i++) {
$values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['status'][$i] . '")';
}
$sql4 = "INSERT INTO working_day(day,status) VALUES " . implode(',', $values);
$result4=mysqli_query($connection,$sql4);
}
if insert more than two different value also like this?
– Benjamin Y
Nov 26 '18 at 5:50
depend on the situation. i am not understanding your case clearly. please explain more or show me the code.
– Parvej Alam
Nov 26 '18 at 6:14
like this $values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['start_time'][$i] . '","' . $_POST['working']['end_time'][$i] . '","' . $_POST['working']['status'][$i] . '")';
– Benjamin Y
Nov 27 '18 at 20:45
yes we can insert as many as we want to add.
– Parvej Alam
Nov 28 '18 at 5:22
add a comment |
Correct way is given below :-
<?php
require_once "config.php";
if(isset($_POST['save'])){
$values = array();
for($i=0 ; $i <count($_POST['working']['day']); $i++) {
$values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['status'][$i] . '")';
}
$sql4 = "INSERT INTO working_day(day,status) VALUES " . implode(',', $values);
$result4=mysqli_query($connection,$sql4);
}
Correct way is given below :-
<?php
require_once "config.php";
if(isset($_POST['save'])){
$values = array();
for($i=0 ; $i <count($_POST['working']['day']); $i++) {
$values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['status'][$i] . '")';
}
$sql4 = "INSERT INTO working_day(day,status) VALUES " . implode(',', $values);
$result4=mysqli_query($connection,$sql4);
}
answered Nov 26 '18 at 5:41
Parvej AlamParvej Alam
2167
2167
if insert more than two different value also like this?
– Benjamin Y
Nov 26 '18 at 5:50
depend on the situation. i am not understanding your case clearly. please explain more or show me the code.
– Parvej Alam
Nov 26 '18 at 6:14
like this $values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['start_time'][$i] . '","' . $_POST['working']['end_time'][$i] . '","' . $_POST['working']['status'][$i] . '")';
– Benjamin Y
Nov 27 '18 at 20:45
yes we can insert as many as we want to add.
– Parvej Alam
Nov 28 '18 at 5:22
add a comment |
if insert more than two different value also like this?
– Benjamin Y
Nov 26 '18 at 5:50
depend on the situation. i am not understanding your case clearly. please explain more or show me the code.
– Parvej Alam
Nov 26 '18 at 6:14
like this $values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['start_time'][$i] . '","' . $_POST['working']['end_time'][$i] . '","' . $_POST['working']['status'][$i] . '")';
– Benjamin Y
Nov 27 '18 at 20:45
yes we can insert as many as we want to add.
– Parvej Alam
Nov 28 '18 at 5:22
if insert more than two different value also like this?
– Benjamin Y
Nov 26 '18 at 5:50
if insert more than two different value also like this?
– Benjamin Y
Nov 26 '18 at 5:50
depend on the situation. i am not understanding your case clearly. please explain more or show me the code.
– Parvej Alam
Nov 26 '18 at 6:14
depend on the situation. i am not understanding your case clearly. please explain more or show me the code.
– Parvej Alam
Nov 26 '18 at 6:14
like this $values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['start_time'][$i] . '","' . $_POST['working']['end_time'][$i] . '","' . $_POST['working']['status'][$i] . '")';
– Benjamin Y
Nov 27 '18 at 20:45
like this $values = '("' . $_POST['working']['day'][$i] . '","' . $_POST['working']['start_time'][$i] . '","' . $_POST['working']['end_time'][$i] . '","' . $_POST['working']['status'][$i] . '")';
– Benjamin Y
Nov 27 '18 at 20:45
yes we can insert as many as we want to add.
– Parvej Alam
Nov 28 '18 at 5:22
yes we can insert as many as we want to add.
– Parvej Alam
Nov 28 '18 at 5:22
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%2f53475150%2fonly-can-insert-first-and-second-value-other-value-cannot-insert-in-database-ho%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
What does error reporting tell you? What are the values being passed in? What is the query that is executed? Hard to tell as is. Also you are open to SQL injections. Use the prepared statements and parameterize the query.
– user3783243
Nov 26 '18 at 5:26
no any error message. when i submit the form only can get array[0] and array[1] value insert to database other cannot get
– Benjamin Y
Nov 26 '18 at 5:33
Use the
mysqli
error reporting function. It sounds like you are not accessing the right level. I would doday
andstatus
rather than the multilevel arrays. Rather than just executing your query. Output it as it is generated and see where you're going wrong. No point in execution the incorrect query. Comment out the execution.– user3783243
Nov 26 '18 at 5:37