简体   繁体   English

php mysql插入数据,但它处于while循环中

[英]php mysql insert the data, but it was in a while loop

i have this data and im calling it using mysql select then while row fetch array 我有此数据,并使用mysql select调用它,然后在行提取数组时

here is my image of the database 这是我的数据库图像 在此处输入图片说明

on top of that database there is save button so when i do save the data, it only save the first row but not the second row. 在该数据库的顶部有一个保存按钮,因此当我保存数据时,它仅保存第一行,而不保存第二行。

here is my insert code its kinda long data 这是我的insert code有点长的数据

// COUNTER
$cou = $_POST['cou'];

// USER DETAILS
$user_code = $_POST['user_code'];
$com_code = $_POST['ccode'];    
$com_for_track = $_POST['atrack'];
$template_code = $_POST['template_code'];

$logo_position = $_POST['logo_position'];
$logo_width = $_POST['logo_width'];

$add_position = $_POST['add_position'];
$font_size = $_POST['font_size'];
$font_family = $_POST['font_family'];

// FOR COMPANY NAME
$com_name = $_POST['com_name'];
$address = $_POST['address'];
$post_code = $_POST['post_code'];
$city = $_POST['city'];
$country = $_POST['country'];
$email = $_POST['email'];
$kvk_no = $_POST['kvk_no'];
$vat_no = $_POST['vat_no'];
$bank_acct = $_POST['bank_acct'];
$bank_acct_iban = $_POST['bank_acct_iban'];

// CLIENT NAME
$com_name_for = $_POST['com_name_for'];
$sub_quo = $_POST['sub_quo'];
$street_name_for = $_POST['street_name_for'];
$post_code_for = $_POST['post_code_for'];
$city_for = $_POST['city_for'];
$country_for = $_POST['country_for'];

$todays = date( 'Y-m-d', strtotime( $_POST['todays'] ) );
$ex_date = date( 'Y-m-d', strtotime( $_POST['ex_date'] ) );

$fact_year = $_POST['fact_year'];
$inv_num = $_POST['inv_num'];

// COMPUTATION
$quan = $_POST['quan'];
$defi = $_POST['defi'];
$amti = $_POST['amti'];
$tota = $_POST['tota'];
$btwi = $_POST['btwi'];

// SUBTOTAL
$total_f = $_POST['total_f'];
$s_btw = $_POST['s_btw'];
$t_com = $_POST['t_com'];

// FOOTER 
$ft = $_POST['ft'];

$i = 1;
while ( $i <= $cou ) {
JON_SQL( "INSERT INTO jon_tem VALUE( ''
,'$user_code'
,'$com_code'
,'$com_for_track'
,'$template_code'
,'$logo_position'
,'$logo_width'
,'$add_position'
,'$font_size'
,'$font_family'
,'$com_name'
,'$address'
,'$post_code'
,'$city'
,'$country'
,'$email'
,'$kvk_no'
,'$vat_no'
,'$bank_acct'
,'$bank_acct_iban'
,'$com_name_for'
,'$sub_quo'
,'$street_name_for'
,'$post_code_for'
,'$city_for'
,'$country_for'
,'$todays'
,'$ex_date'
,'$fact_year'
,'$inv_num'
,'$quan'
,'$defi'
,'$amti'
,'$tota'
,'$btwi'
,'$total_f'
,'$s_btw'
,'$t_com'
,NOW() )" );

$i++;
}

echo '<div id="success">New template has been saved! <a href="index.php?c=cprof">Quotation Settings</a></div>';

if you see i put while there but its not workin, well yes its working and it loop it 3 times or bla bla but again it only save the first row data. 如果您看到我放在while there但它不起作用,是的,它的工作原理是,它循环了3次或bla bla,但再次它仅保存了第一行数据。

how can i fix it? 我该如何解决? :( :(

您在发送单个元素的区域中,必须发送数据数组以保存数据数组。

I finaly fixed it. 我最终解决了它。

heres is the updated code. 这是更新的代码。

$i = 1;
while ( $i <= $cou ) {

// COMPUTATION
$quan = $_POST['quan_'.$i];
$defi = $_POST['defi_'.$i];
$amti = $_POST['amti_'.$i];
$tota = $_POST['tota_'.$i];
$btwi = $_POST['btwi_'.$i];

JON_SQL( "INSERT INTO jon_tem VALUE( ''
,'$user_code'
,'$com_code'
,'$com_for_track'
,'$template_code'
,'$logo_position'
,'$logo_width'
,'$add_position'
,'$font_size'
,'$font_family'
,'$com_name'
,'$address'
,'$post_code'
,'$city'
,'$country'
,'$email'
,'$kvk_no'
,'$vat_no'
,'$bank_acct'
,'$bank_acct_iban'
,'$com_name_for'
,'$sub_quo'
,'$street_name_for'
,'$post_code_for'
,'$city_for'
,'$country_for'
,'$todays'
,'$ex_date'
,'$fact_year'
,'$inv_num'
,'$quan'
,'$defi'
,'$amti'
,'$tota'
,'$btwi'
,'$total_f'
,'$s_btw'
,'$t_com'
,NOW() )" );

$i++;
}

and the html code 和html代码

$i = 1;
while( $row = mysql_fetch_array( $sqlview ) ) {
?>
    <tr>
        <td><?=$row['category'];?></td>
        <td>
            <input type="hidden" name="atrack" value="<?=$row['com_track'];?>" />
            <input type="hidden" name="quan_<?=$i;?>" value="<?=$row['quo_quantity'];?>" />
            <input type="hidden" name="defi_<?=$i;?>" value="<?=$row['quo_definition'];?>" />
            <input type="hidden" name="amti_<?=$i;?>" value="<?=$row['quo_amt'];?>" />
            <input type="hidden" name="tota_<?=$i;?>" value="<?=$row['quo_total'];?>" />
            <input type="hidden" name="btwi_<?=$i;?>" value="<?=$row['quo_btw'];?>" />
            <?=$row['quo_quantity'];?> x
        </td>
        <td width="200">
            <?=$row['quo_definition'];?>
        </td>
        <td>
            <?=$msg_tot;?> <?=$row['quo_amt'];?>
        </td>
        <td id="total">
            <input type="hidden" name="sumof" value="<?=$row['quo_total'];?>" />
            <?=$msg_tot;?> <?=$row['quo_total'];?>
        </td>
        <td>
            <?=$row['quo_btw'];?>
        </td>
    </tr>
 <?
 $i++;
}

thank you guys for the idea. 谢谢你们的主意。 very appreciate it. 非常感谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM