php mysql (INSERT QUERY) -
i have simple payment form , include voucher_id
, customer_id
, amount
, payment_type
, transaction_type
, date
.
transaction_type’s withdrawls , deposits.
my data base table should not contain "amount" column. has credit , debit column. in case, want insert
amount debit
column if transaction type ="withdraws"
of insert
amount credit column if transaction_type ="deposits"
.
when insert
data table show:
column count doesn't match value count @ row 1
because, table has debit , credit column. form has 1 column , name amount. how can insert query sort out question.
<?php // save data if form submitted if(isset($_post['submitted'])){ // catch data $voucher_numebr = $_post['voucher_numebr']; $member_id = $_post['member_id']; $amount = $_post['amount']; $acc_type = $_post['acc_type']; $payment_type = $_post['payment_type']; $discription = $_post['discription']; $created = date("y-m-d h:i:s"); // $balance = $_post['balance']; $tranaction_type = $_post['tranaction_type']; $balance="not define"; //insert tbl_customer_account if($tranaction_type == "withdrawls."){ //echo "1"; $sql ='insert tbl_customer_account values(null,"'.$voucher_numebr.'","'.$member_id.'","'.$amount.'","'.$acc_type.'","'.$payment_type.'","'.$discription.'","'.$created.'","'.$tranaction_type.'","'.$balance.'")'; } else{ $sql ='insert tbl_customer_account values(null,"'.$voucher_numebr.'","'.$member_id.'","'.$amount.'","'.$acc_type.'","'.$payment_type.'","'.$discription.'","'.$created.'")'; } //else{ //} mysql_query($sql, $conn) or die(mysql_error()); echo 'form submitted'; echo '<br />'; echo mysql_affected_rows(); die(); } ?>
since you're not specifying value each column, have specify columns you're updating. practice when updating columns, don't have worry future changes table's structure (e.g., adding or moving columns).
you haven't included table structure, i'll have guess column names:
if($tranaction_type == "withdrawls."){ //echo "1"; $sql ='insert tbl_customer_account (some_field, voucher_number, member_id, debits, account_type, payment_type, description, created, transaction_type, balance) values(null,"'.$voucher_numebr.'","'.$member_id.'","'.$amount.'","'.$acc_type.'","'.$payment_type.'","'.$discription.'","'.$created.'","'.$tranaction_type.'","'.$balance.'")'; } else{ $sql ='insert tbl_customer_account (some_field, voucher_number, member_id, credits, account_type, payment_type, description, created) values(null,"'.$voucher_numebr.'","'.$member_id.'","'.$amount.'","'.$acc_type.'","'.$payment_type.'","'.$discription.'","'.$created.'")'; }
i suppose there's reason you're leaving out transaction_type
, balance
deposits?
Comments
Post a Comment