0

Hai. i'm beginner in php. Can someone help me to insert the calculated value into database. I'm trying to insert calculated value into database but it doesn't work. This is my code.

<?php 
$ic=$_SESSION['ic'];

$query=" SELECT * FROM form WHERE ic='$ic'";
$result=mysql_query($query);
$record=mysql_fetch_array($result);

$query1=" SELECT * FROM login WHERE userIC='$ic'";
$result1=mysql_query($query1);
$record2=mysql_fetch_array($result1);

?>

    <?php
error_reporting(E_ALL & ~E_NOTICE);

$no1=$_POST[asal1];
$no2=$_POST[tuntutan1];
$tolak1=$_POST[baki1];

$tolak1=($no1-$no2);
 ?>
    <?php
error_reporting(E_ALL & ~E_NOTICE);

$no1=$_POST[asal2];
$no2=$_POST[tuntutan2];
$tolak2=$_POST[baki2];

$tolak2=($no1-$no2);
 ?>

  <?php
error_reporting(E_ALL & ~E_NOTICE);

$no1=$_POST[asal3];
$no2=$_POST[tuntutan3];
$tolak3=$_POST[baki3];

$tolak3=($no1-$no2);
 ?>

  <?php
error_reporting(E_ALL & ~E_NOTICE);

$no1=$_POST[asal4];
$no2=$_POST[tuntutan4];
$tolak4=$_POST[baki4];

$tolak4=($no1-$no2);
 ?>

  <?php
error_reporting(E_ALL & ~E_NOTICE);

$no1=$_POST[asal5];
$no2=$_POST[tuntutan5];
$tolak5=$_POST[baki5];

$tolak5=($no1-$no2);
 ?>

  <?php
error_reporting(E_ALL & ~E_NOTICE);

$no1=$_POST[asal6];
$no2=$_POST[tuntutan6];
$tolak6=$_POST[baki6];

$tolak6=($no1-$no2);
 ?>



<p>&nbsp;</p>
<table width="1000"  border="1" cellpadding="4" cellspacing="0" bordercolor="#000000"bgcolor="#FFFF66" align="center">
<td height="48" colspan="8"   bgcolor="#CCCCCC" class="main_menu2"><div align="center"><strong>LAPORAN KEMAJUAN</strong></div></td>
  <tr bgcolor="#FFCC00" class="text">
    <td colspan="2" bgcolor="#A5E1E4">C. BELANJAWAN ASAL PROJEK</td>
  </tr>
   <tr class="text">
    <td  hidden="" bgcolor="#ffffff">Kod</td>
    <td  hidden="" bgcolor="#ffffff"><input name="kod" type="text" id="kod" onKeyUp="javascript:this.value=this.value.toUpperCase();" value="<?php echo $record["kod"]; ?>" size="25" maxlength="12" ></td>
  </tr>
 <th width="188" scope="col" bgcolor="#FFFF66">Bahagian Perbelanjaan Projek</th>
    <th width="120" scope="col" bgcolor="#FFFF66">Peruntukan asal</th>
    <th width="155" scope="col" bgcolor="#FFFF66">Tuntutan</th>
     <th width="155" scope="col" bgcolor="#FFFF66">Baki</th>
  </tr>
  <tr>
    <td><p>Vot 11000 (Gaji dan upah)</p></td>
    <td><input type="text" name="asal1" id="asal1" readonly="readonly" value="<?php echo $record["asal1"]; ?>" /></td>
    <td><input type="text" name="tuntutan1" id="tuntutan1" readonly="readonly"   value="<?php echo $record["tuntutan1"]; ?>" /></td>
    <td><input type="text" name="baki1" id="baki1" value="<?php  echo $tolak1;
 ?>" /></td> 

   </tr>

  <tr>
    <td>Vot 14000 (Elaun lebih masa)</td>
    <td><input type="text" name="asal2" id="asal2"  readonly="readonly" value="<?php echo $record["asal2"]; ?>" /></td></td>
    <td><input type="text" name="tuntutan2" id="tuntutan2" readonly="readonly"  value="<?php echo $record["tuntutan2"]; ?>" /></td>
    <td><input type="text" name="baki2" id="baki2" value="<?php  echo $tolak2;
 ?>" /></td> 
  </tr>
  <tr>
    <td>Vot 21000 (Perjalanan dan sewa kenderaan)</td>
    <td><input type="text" name="asal3" id="asal3"  readonly="readonly" value="<?php echo $record["asal3"]; ?>" /></td></td>
    <td><input type="text" name="tuntutan3" id="tuntutan3" readonly="readonly"  value="<?php echo $record["tuntutan3"]; ?>" /></td>
    <td><input type="text" name="baki3" id="baki3" value="<?php  echo $tolak3;
 ?>" /></td>
  </tr>
  <tr>
    <td>Vot 27000 (Bekalan dan bahan lain)</td>
    <td><input type="text" name="asal4" id="asal4"  readonly="readonly" value="<?php echo $record["asal4"]; ?>" /></td></td>
    <td><input type="text" name="tuntutan4" id="tuntutan4" readonly="readonly"  value="<?php echo $record["tuntutan4"]; ?>" /></td>
    <td><input type="text" name="baki4" id="baki4" value="<?php  echo $tolak4;
 ?>" /></td>
  </tr>
  <tr>
    <td>Vot 29000 (Perkhidmatan iktisas dan hospitaliti)</td>
    <td><input type="text" name="asal5" id="asal5"  readonly="readonly" value="<?php echo $record["asal5"]; ?>" /></td></td>
    <td><input type="text" name="tuntutan5" id="tuntutan5" readonly="readonly"  value="<?php echo $record["tuntutan5"]; ?>" /></td>
     <td><input type="text" name="baki5" id="baki5" value="<?php  echo $tolak5;
 ?>" /></td>
  </tr>
  <tr>
    <td>Vot 35000 (harta modal)</td>
    <td><input type="text" name="asal6" id="asal6"  readonly="readonly" value="<?php echo $record["asal6"]; ?>" /></td></td>
    <td><input type="text" name="tuntutan6" id="tuntutan6" readonly="readonly"  value="<?php echo $record["tuntutan6"]; ?>" /></td>
    <td><input type="text" name="baki6" id="baki6" value="<?php  echo $tolak6;
 ?>" /></td>
  </tr>
  <tr>
    <td>Jumlah</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

 <label>
   <center> 
     <p>
       <input type="submit" name="submit" id="submit" value="Kira" />
     </p></center>
    </label>
2
Contributors
1
Reply
9
Views
1 Year
Discussion Span
Last Post by AleMonteiro
0

No where in your code exists an INSERT...

But let's say you want to insert $tolak..

$no1=$_POST[asal6];
$no2=$_POST[tuntutan6];
$tolak6=$_POST[baki6];
$tolak6=($no1-$no2);

$sql = "INSERT INTO table_name(col1, col2, col3) VALUES($no1, $no2, $tolak6);";

// Assuming that you're using MySQL:
$result = mysql_query($sql) OR die("Error: " . mysql_error());
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.