Inserting Data in multiple tables In database Using If statement and array
i'm beginner in PHP and i having problems with my code..i want to make a little fee and income system.its a web based app.. i want to insert data in two different tables 1) fees and 2)income using options..here im taking two steps (1) select data from database (2) inserting in data base.
1st step is working good problem with 2nd step the data is inserted in both 1) fees and 2)income, not all records saved i click for saving 3 records but there is only one or two record save.
select data from database
<?php
if(isset($_POST['classes'])){
$cla=$_POST['classes'];}$sql = "SELECT class,std_name,roll_no,monthly_fee from students where class = '$cla'";
$result = $conn->query($sql);if ($result->num_rows > 0) {$counter = 0;while($row = $result->fetch_assoc()) {?><tr><td><?php echo $row["roll_no"]; ?><input type="hidden" value="<?php echo $row["roll_no"]; ?>" name="roll_no"></td><td><?php echo $row["std_name"]; ?><input type="hidden" value="<?php echo$row["std_name"]; ?>" name="std_name"></td><td><?php echo $row["class"]; ?><input type="hidden" value="<?php echo $row["class"]; ?>" name="class"></td><td><?php echo $row["monthly_fee"]; ?><input type="hidden" value="<?php echo$row["monthly_fee"]; ?>" name="monthly_fee"></td><td><select name="status[<?php echo $counter; ?>]"><option >--Select Status--</option>
<option value="Paid">Paid</option>
<option value="Unpaid">Unpaid</option>
Insert into Database
i think the problems is with this code
here i want to store data with condition
if (isset($_POST['submit'])) {
foreach ($_POST['status'] as $state => $status) {
$roll_no = $_POST['roll_no'][$state];
$std_name = $_POST['std_name'][$state];
$class = $_POST['class'][$state];
$monthly_fee = $_POST['monthly_fee'][$state];
$stat = $_POST['status'][$state];
$date = date('Y-m-d H:i:s');
$sql = "INSERT INTO fees(std_id,std_name,std_class,fee_status,monthly_fee,taken_date) VALUES( '$roll_no','$std_name','$class','$stat','$monthly_fee','$date')";
if ($state == 'Paid') {
$sql = "INSERT INTO income(std_fee) values ('$monthly_fee')";if ($conn->query($sql) === TRUE) {$flag = 1;}else{echo "error".$sql."<br>".$conn->error;} }}}?>
i hope you will understand
php sql arrays html5
add a comment |
i'm beginner in PHP and i having problems with my code..i want to make a little fee and income system.its a web based app.. i want to insert data in two different tables 1) fees and 2)income using options..here im taking two steps (1) select data from database (2) inserting in data base.
1st step is working good problem with 2nd step the data is inserted in both 1) fees and 2)income, not all records saved i click for saving 3 records but there is only one or two record save.
select data from database
<?php
if(isset($_POST['classes'])){
$cla=$_POST['classes'];}$sql = "SELECT class,std_name,roll_no,monthly_fee from students where class = '$cla'";
$result = $conn->query($sql);if ($result->num_rows > 0) {$counter = 0;while($row = $result->fetch_assoc()) {?><tr><td><?php echo $row["roll_no"]; ?><input type="hidden" value="<?php echo $row["roll_no"]; ?>" name="roll_no"></td><td><?php echo $row["std_name"]; ?><input type="hidden" value="<?php echo$row["std_name"]; ?>" name="std_name"></td><td><?php echo $row["class"]; ?><input type="hidden" value="<?php echo $row["class"]; ?>" name="class"></td><td><?php echo $row["monthly_fee"]; ?><input type="hidden" value="<?php echo$row["monthly_fee"]; ?>" name="monthly_fee"></td><td><select name="status[<?php echo $counter; ?>]"><option >--Select Status--</option>
<option value="Paid">Paid</option>
<option value="Unpaid">Unpaid</option>
Insert into Database
i think the problems is with this code
here i want to store data with condition
if (isset($_POST['submit'])) {
foreach ($_POST['status'] as $state => $status) {
$roll_no = $_POST['roll_no'][$state];
$std_name = $_POST['std_name'][$state];
$class = $_POST['class'][$state];
$monthly_fee = $_POST['monthly_fee'][$state];
$stat = $_POST['status'][$state];
$date = date('Y-m-d H:i:s');
$sql = "INSERT INTO fees(std_id,std_name,std_class,fee_status,monthly_fee,taken_date) VALUES( '$roll_no','$std_name','$class','$stat','$monthly_fee','$date')";
if ($state == 'Paid') {
$sql = "INSERT INTO income(std_fee) values ('$monthly_fee')";if ($conn->query($sql) === TRUE) {$flag = 1;}else{echo "error".$sql."<br>".$conn->error;} }}}?>
i hope you will understand
php sql arrays html5
2
Can you format your code properly as it is currently loads of commands on single lines.
– Nigel Ren
Nov 19 '18 at 19:57
add a comment |
i'm beginner in PHP and i having problems with my code..i want to make a little fee and income system.its a web based app.. i want to insert data in two different tables 1) fees and 2)income using options..here im taking two steps (1) select data from database (2) inserting in data base.
1st step is working good problem with 2nd step the data is inserted in both 1) fees and 2)income, not all records saved i click for saving 3 records but there is only one or two record save.
select data from database
<?php
if(isset($_POST['classes'])){
$cla=$_POST['classes'];}$sql = "SELECT class,std_name,roll_no,monthly_fee from students where class = '$cla'";
$result = $conn->query($sql);if ($result->num_rows > 0) {$counter = 0;while($row = $result->fetch_assoc()) {?><tr><td><?php echo $row["roll_no"]; ?><input type="hidden" value="<?php echo $row["roll_no"]; ?>" name="roll_no"></td><td><?php echo $row["std_name"]; ?><input type="hidden" value="<?php echo$row["std_name"]; ?>" name="std_name"></td><td><?php echo $row["class"]; ?><input type="hidden" value="<?php echo $row["class"]; ?>" name="class"></td><td><?php echo $row["monthly_fee"]; ?><input type="hidden" value="<?php echo$row["monthly_fee"]; ?>" name="monthly_fee"></td><td><select name="status[<?php echo $counter; ?>]"><option >--Select Status--</option>
<option value="Paid">Paid</option>
<option value="Unpaid">Unpaid</option>
Insert into Database
i think the problems is with this code
here i want to store data with condition
if (isset($_POST['submit'])) {
foreach ($_POST['status'] as $state => $status) {
$roll_no = $_POST['roll_no'][$state];
$std_name = $_POST['std_name'][$state];
$class = $_POST['class'][$state];
$monthly_fee = $_POST['monthly_fee'][$state];
$stat = $_POST['status'][$state];
$date = date('Y-m-d H:i:s');
$sql = "INSERT INTO fees(std_id,std_name,std_class,fee_status,monthly_fee,taken_date) VALUES( '$roll_no','$std_name','$class','$stat','$monthly_fee','$date')";
if ($state == 'Paid') {
$sql = "INSERT INTO income(std_fee) values ('$monthly_fee')";if ($conn->query($sql) === TRUE) {$flag = 1;}else{echo "error".$sql."<br>".$conn->error;} }}}?>
i hope you will understand
php sql arrays html5
i'm beginner in PHP and i having problems with my code..i want to make a little fee and income system.its a web based app.. i want to insert data in two different tables 1) fees and 2)income using options..here im taking two steps (1) select data from database (2) inserting in data base.
1st step is working good problem with 2nd step the data is inserted in both 1) fees and 2)income, not all records saved i click for saving 3 records but there is only one or two record save.
select data from database
<?php
if(isset($_POST['classes'])){
$cla=$_POST['classes'];}$sql = "SELECT class,std_name,roll_no,monthly_fee from students where class = '$cla'";
$result = $conn->query($sql);if ($result->num_rows > 0) {$counter = 0;while($row = $result->fetch_assoc()) {?><tr><td><?php echo $row["roll_no"]; ?><input type="hidden" value="<?php echo $row["roll_no"]; ?>" name="roll_no"></td><td><?php echo $row["std_name"]; ?><input type="hidden" value="<?php echo$row["std_name"]; ?>" name="std_name"></td><td><?php echo $row["class"]; ?><input type="hidden" value="<?php echo $row["class"]; ?>" name="class"></td><td><?php echo $row["monthly_fee"]; ?><input type="hidden" value="<?php echo$row["monthly_fee"]; ?>" name="monthly_fee"></td><td><select name="status[<?php echo $counter; ?>]"><option >--Select Status--</option>
<option value="Paid">Paid</option>
<option value="Unpaid">Unpaid</option>
Insert into Database
i think the problems is with this code
here i want to store data with condition
if (isset($_POST['submit'])) {
foreach ($_POST['status'] as $state => $status) {
$roll_no = $_POST['roll_no'][$state];
$std_name = $_POST['std_name'][$state];
$class = $_POST['class'][$state];
$monthly_fee = $_POST['monthly_fee'][$state];
$stat = $_POST['status'][$state];
$date = date('Y-m-d H:i:s');
$sql = "INSERT INTO fees(std_id,std_name,std_class,fee_status,monthly_fee,taken_date) VALUES( '$roll_no','$std_name','$class','$stat','$monthly_fee','$date')";
if ($state == 'Paid') {
$sql = "INSERT INTO income(std_fee) values ('$monthly_fee')";if ($conn->query($sql) === TRUE) {$flag = 1;}else{echo "error".$sql."<br>".$conn->error;} }}}?>
i hope you will understand
php sql arrays html5
php sql arrays html5
asked Nov 19 '18 at 19:44
Atif RajaAtif Raja
126
126
2
Can you format your code properly as it is currently loads of commands on single lines.
– Nigel Ren
Nov 19 '18 at 19:57
add a comment |
2
Can you format your code properly as it is currently loads of commands on single lines.
– Nigel Ren
Nov 19 '18 at 19:57
2
2
Can you format your code properly as it is currently loads of commands on single lines.
– Nigel Ren
Nov 19 '18 at 19:57
Can you format your code properly as it is currently loads of commands on single lines.
– Nigel Ren
Nov 19 '18 at 19:57
add a comment |
0
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%2f53381606%2finserting-data-in-multiple-tables-in-database-using-if-statement-and-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
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.
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%2f53381606%2finserting-data-in-multiple-tables-in-database-using-if-statement-and-array%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
2
Can you format your code properly as it is currently loads of commands on single lines.
– Nigel Ren
Nov 19 '18 at 19:57