我有問題將值保存到mysql數據庫作爲輸入值無法進入varables.Please幫助我。
我喜歡這個PHP用字符串輸入字段值保存到mySql數據庫
<td> <?php
$targets = new Target();
$alltargets = $targets-> getBranches();
foreach($alltargets as $target){
echo "<tr>"; echo "<td>"; echo $target['code']; echo "</td>"; echo " <td>"; echo '<input type="text" value="" onKeyUp = "myFunction(this)" name="'. $target['code'] . '" id="'. $target['code'] . '_percentage" class="input-block- level" autocomplete="off" required/>'; echo "</td>"; echo "<td>"; echo '<input type="text" value="" name="' . $target['code'] . '" id="'.$target['code'] . '_amount" class="input-block-level" autocomplete="off" required/>'; echo " </td>"; echo "</tr>";
$targets = new Target();
$branch = $target['code'];
$percentage = $target['code'] . '_percentage;
$amount = $target['code'] . '_amount;
$targets-> saveBranchTargets($branch, $percentage, $amount);
$messagetoshow = "Update Successfully";
}
?>
</td>
</tr>
</tbody>
</table>
<input type="submit" class="btn" value="Save"/>
</div>
</form>
</div>
<script>
var percentage = 0;
function myFunction(element){
var v1 = document.getElementById('totalamount').value;
var v2 = element.value;
var percentage = parseInt(v1) * parseInt(v2)/100;
var idString = element.getAttribute("id");
var amountId = idString.substr(0, idString.indexOf('_')) + '_amount';
console.log(amountId);
document.getElementById(amountId).value = percentage;
}
</script>
<?php
require_once代碼( '包括/ MysqliDb.php');
類目標{
public function __construct() {
}
public function saveBranchTargets($branch, $percentage, $amount){
$this->branch = $branch;
$this->percentage = $percentage;
$this->amount = $amount;
$db = new Mysqlidb();
$data_branchtargets = array(
'branch' => $this->branch,
'percentage' => $this->percentage,
'amount' => $this->amount,
);
$this->id = $db->insert('store_targets', $data_branchtargets);
}
}
數據未插入到我的數據庫中正確,因爲他們沒有將其設置爲變量正確。
什麼是Target類?不知道'saveBranchTargets()'函數是如何工作的,這個問題就不能回答。 –