Извините за мой плохой английский.
Как мне вставить таблицу базы данных и одновременно обновить другую таблицу базы данных? Я хочу вставить новую запись «доход», в то время как я делаю это, я хочу, чтобы таблица счетов, в которую был добавлен доход, будет обновляться с текущим балансом счета + новым счетом дохода. Есть ли более простые методы?
Это мой php код
// Add New Entry
if (isset($_POST['submit']) && $_POST['submit'] == 'saveEntry') {
// User Validations
if($_POST['money_income_id'] == '...') {
$msgBox = alertBox($catReq, "<i class='fa fa-times-circle'></i>", "alert-danger");
} else if($_POST['money_income_description'] == '') {
$msgBox = alertBox($money_income_descriptionReq, "<i class='fa fa-times-circle'></i>", "alert-danger");
} else if($_POST['money_accounts_catogerytitles'] == '...') {
$msgBox = alertBox('Failed! Income Account Needed', "<i class='fa fa-times-circle'></i>", "alert-danger");
} else if($_POST['money_income_amount'] == '...') {
$msgBox = alertBox('Failed! Amount Needed', "<i class='fa fa-times-circle'></i>", "alert-danger");
} else if($_POST['money_income_time'] == '...') {
$msgBox = alertBox('Failed! Time Needed', "<i class='fa fa-times-circle'></i>", "alert-danger");
} else if($_POST['money_payer_title'] == '...') {
$msgBox = alertBox('Failed! Payer Needed', "<i class='fa fa-times-circle'></i>", "alert-danger");
} else if($_POST['money_incomecategory_title'] == '...') {
$msgBox = alertBox('Failed! Income Category Needed', "<i class='fa fa-times-circle'></i>", "alert-danger");
} else if($_POST['money_paymentmethod_title'] == '...') {
$msgBox = alertBox('Failed! Payment Method Needed', "<i class='fa fa-times-circle'></i>", "alert-danger");
} else {
$money_income_account = $_POST['money_accounts_catogerytitles'];
$money_income_description = encodeIt($_POST['money_income_description']);
$money_income_amount = $_POST['money_income_amount'];
$money_income_time = $_POST['money_income_time'];
$money_income_payer = $_POST['money_payer_title'];
$money_income_category = $_POST['money_incomecategory_title'];
$money_income_paymentmethod = $_POST['money_paymentmethod_title'];
$stmt = $mysqli->prepare("INSERT INTO
money_income(
money_income_account,
id,
money_income_description,
money_income_amount,
money_income_time,
money_income_payer,
money_income_category,
money_income_paymentmethod,
school_income_date,
school_income_ipaddress
) VALUES (
?,
?,
?,
?,
?,
?,
?,
?,
?,
?
)
");
$stmt->bind_param('ssssssssss',
$money_income_account,
$pw_userId,
$money_income_description,
$money_income_amount,
$money_income_time,
$money_income_payer,
$money_income_category,
$money_income_paymentmethod,
$todayDt,
$actIp
);
$stmt = $mysqli->prepare("UPDATE
money_accounts
SET
money_accounts_catogeryamount = ?,
money_accounts_catogerylastupdated = ?
WHERE
money_accounts_catogeryid = ?");
$stmt->bind_param('sss',
$money_income_amount,
$todayDt,
$money_income_account
);$stmt->execute();
$stmt->close();
header('index.php?page=income');
// Add Recent Activity
$activityType = '8';
$activityTitle = $newEntryNavLink.' "'.decodeit($money_income_description).' '.$createdText;
updateActivity($pw_userId,$activityType,$activityTitle);
$msgBox = alertBox('New income entry '."<b>\"".decodeit($money_income_description)."\"</b> ".$newcatMsg2, "<i class='fa fa-check-square'></i>", "alert-success");// Clear the Form of values
$_POST['money_income_description'] = $_POST['money_income_amount'] = $_POST['money_income_time'] = '';
}
}
?>
Это мой HTML-код
<div class="modal fade slide-up disable-scroll" id="addNewAppModal" tabindex="-1" role="dialog" aria-labelledby="addNewAppModal" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content-wrapper">
<div class="modal-content">
<div class="modal-header clearfix ">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-14"></i>
</button>
<h4 class="p-b-5"><span class="semi-bold">New</span> Income</h4>
</div>
<div class="modal-body">
<p class="small-text text-center">Create a new income using this form, make sure you fill them all</p>
<form action="" method="post">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="money_income_description">Description</label>
<input type="text" class="form-control" name="money_income_description" required="required" value="<?php echo isset($_POST['money_income_description']) ? $_POST['money_income_description'] : ''; ?>" />
<span class="help-block"><?php echo $money_income_descriptionHelp; ?></span>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="money_income_amount">Amount</label>
<input type="number" class="form-control" name="money_income_amount" required="required" value="<?php echo isset($_POST['money_income_amount']) ? $_POST['money_income_amount'] : ''; ?>" />
<span class="help-block"><?php echo $money_income_descriptionHelp; ?></span>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="money_income_time">Time</label>
<input id="date" type="text" name="money_income_time" required="required" class="form-control input-sm" value="<?php echo isset($_POST['money_income_time']) ? $_POST['money_income_time'] : ''; ?>" id="startDate">
<span class="help-block"><?php echo $money_income_descriptionHelp; ?></span>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<div class="form-group">
<label for="money_accounts_catogerytitles">Select Account</label>
<select class="cs-select cs-skin-slide" required="required" data-init-plugin="cs-select" name="money_accounts_catogerytitles" id="money_accounts_catogerytitles">
<option value="...">Select</option>
<?php
$sqlStmt = "SELECT
money_accounts_catogeryid,
money_accounts_catogerytitles,
UNIX_TIMESTAMP(money_accounts_catogerydate) AS income3Date
FROM
money_accounts
WHERE
id = ".$pw_userId."ORDER BY income3Date DESC";
$results = mysqli_query($mysqli, $sqlStmt) or die('-2'.mysqli_error());
?>
<?php while ($row = mysqli_fetch_assoc($results)) { ?>
<option value="<?php echo $row['money_accounts_catogerytitles']; ?>"><?php echo decodeit($row['money_accounts_catogerytitles']); ?></option>
<?php } ?>
</select>
</div>
</div>
Задача ещё не решена.
Других решений пока нет …