2012-12-19 106 views
0

我有這個數據和IM使用MySQL的選擇,然後同時行獲取陣列PHP的MySQL插入數據,但它是在一個while循環

這裏是我的數據庫 enter image description here

的圖像調用它該數據庫的頂部有保存按鈕 所以當我確實保存數據時,它只保存第一行而不保存第二行。

這裏是我的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>'; 

,如果你看到我把while there但它不幹活,也肯定其工作,並循環播放3次或BLA BLA但同樣它只能保存第一行數據。

我該如何解決它? :(

+1

'$ _POST ['bank_acct'];'用這個腳本!?!?!哇。 –

+0

從快速瀏覽代碼的外觀來看,您似乎只會輸入一組數據,即使您可能循環三次,數據是否相同也無關緊要。基本上你只是三次做同樣的事情。 – PhearOfRayne

+0

您正在嘗試將相同的值保存3次;可能是第一次插入行後失敗的獨特約束 –

回答

0

我finaly固定它。

繼承人是更新的代碼。

$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++; 
} 

和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++; 
} 

感謝你們的想法。很欣賞我噸。

1

您發送面積單一稀土元素,你要發送數據的陣列,爲您節省數據的陣列。