PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,446 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,519 people online right now. Registration is fast and FREE... Join Now!




retrieve and update dynamically added rows

 

retrieve and update dynamically added rows

minie

30 Jun, 2009 - 06:34 PM
Post #1

New D.I.C Head
*

Joined: 11 Jun, 2009
Posts: 12

hello everyone...

my task is to make a form which will be populated with the data in db. This data can be edit and new rows can be added to add more info. (dynamically added rows)

ive done the adding and retriveing part.

im having problem doing the updating part.... can anyone help me out please???


daftarhmb.php
CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<script language="javascript" type="text/javascript">
var a=0;
function addRowBhgnB()
{          a++;
          frm2.h4.value=a;
          var tbl = document.getElementById('bhgnBHM');
          var lastRow = tbl.rows.length;
          var iteration = lastRow;
          var row = tbl.insertRow(lastRow);
  
          
           var firstCell = row.insertCell(0);
          var el6 = document.createElement('input');
          el6.type = 'text';
          el6.name = 'bil' + a;
          el6.id = 'bil' + a;
          el6.size = 10;
          el6.maxlength = 10;
          firstCell.appendChild(el6);
          
          var secondCell = row.insertCell(1);
          var el = document.createElement('input');
          el.type = 'text';
          el.name = 'tarikh' + a;
          el.id = 'tarikh' + a;
          el.size = 15;
          el.maxlength = 15;
          secondCell.appendChild(el);
          
          var thirdCell = row.insertCell(2);
          var el2 = document.createElement('input');
          el2.type = 'text';
          el2.name = 'butiran' + a;
          el2.id = 'butiran' + a;
          el2.size = 40;
          el2.maxlength = 40;
          thirdCell.appendChild(el2);

          var fourthCell = row.insertCell(3);
          var el3 = document.createElement('input');
          el3.type = 'text';
          el3.name = 'tempohJaminan' + a;
          el3.id = 'tempohJaminan' + a;
          el3.size = 25;
          el3.maxlength = 25;
          fourthCell.appendChild(el3);
          
          
          var fifthCell = row.insertCell(4);
          var el4 = document.createElement('input');
          el4.type = 'text';
          el4.name = 'kos' + a;
          el4.id = 'kos' + a;
          el4.size = 15;
          el4.maxlength = 15;
          fifthCell.appendChild(el4);
          
          var sixthCell = row.insertCell(5);
          var el5 = document.createElement('input');
          el5.type = 'text';
          el5.name = 'txtRow4' + a;
          el5.id = 'txtRow4' + a;
          el5.size = 60;
          el5.maxlength = 60;
          sixthCell.appendChild(el5);
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title></head>

<body bgcolor="#FFFFCC">
<form action="dhmbSubmit.php" method="post" name="frm2" id="frm2">
<table align="center" border="1" width="1010">
    <tr>
        <td><table align="center" border="1" width="100%" bgcolor="#FFFFFF" bordercolor="#000000">
                <tr>
                    <td colspan="4" align="right"><p><strong>KEW.PA 2</strong></p>
                          <p align="right">( No. Siri Pendaftaran:
          <label>
          <input name="NoSiriPendaftaran2" type="text" id="NoSiriPendaftaran2" size="20" />
          </label>)        </p>
                      <p align="center"><strong>DAFTAR HARTA MODAL</strong></p>
        <p align="center"><strong>BUTIR-BUTIR PENAMBAHAN, PENGGANTIAN DAN NAIKTARAF </strong></p>
        <p align="center">Bahagian B </p></td>
                </tr>
            </table>
        <table width="100%" border="1" align="center" bordercolor="#000000" bgcolor="#FFFFFF" id="bhgnBHM">    
            <tr>
                <td width="3%" align="center" bgcolor="#FFFF99">Bil.</td>
                <td width="10%" align="center" bgcolor="#FFFF99">Tarikh</td>
                <td width="25%" align="center" bgcolor="#FFFF99">Butiran</td>
                <td width="15%" align="center" bgcolor="#FFFF99">Tempoh Jaminan</td>
                <td width="10%" align="center" bgcolor="#FFFF99">Kos (RM) </td>
                <td width="37%" align="center" bgcolor="#FFFF99">Nama dan Tandatangan</td>
            </tr>
            
            <!--<tr valign="top">
                <td>1</td>
                <td><input name="tarikhTambah" type="text" id="tarikhTambah" size="15" maxlength="15" /></td>
                <td><input name="butiran" type="text" id="butiran" size="40" maxlength="40" /></td>
                <td><input name="tempohJaminan" type="text" id="tempohJaminan" size="25" maxlength="25" /></td>
              <td><input name="kos" type="text" id="kos" size="15" maxlength="15" /></td>
                <td><input name="namaTT" type="text" id="namaTT" size="60" maxlength="60" /></td>
                
            </tr>-->
          </table>
          <input type="button" value="Tambah" onclick="addRowBhgnB();" />
        </td>
    </tr>
    
</table>

<table width="1010" border="0" align="center">
    <tr>
        <td align="center"><input name="Submit" type="submit" value="Daftar" />
        <input type="hidden" name="h4" id="h4" />
        </td>
    </tr>
</table>

</form>
</body>
</html>



dhmbSubmit.php
CODE

<?php

include "dbCon.php";

//daftar harta modal


$num4 =  $_POST['h4'];
$NoSiriPendaftaran2=$_POST["NoSiriPendaftaran2"];
echo ($num4);
for($a=1;$a<=$num4;$a++)
{
if(isset($_REQUEST["bil$a"])){$Bil =  $_REQUEST["bil$a"];}
if(isset($_REQUEST["tarikh$a"])){$Tarikh =  $_REQUEST["tarikh$a"];}
if(isset($_REQUEST["butiran$a"])){$Butiran = $_REQUEST["butiran$a"];}/*else{$address= 'address';}*/ //for error controling
if(isset($_REQUEST["tempohJaminan$a"])){$TempohJaminan = $_REQUEST["tempohJaminan$a"];}/*else{$contactNum = 00;}*/ //for error controling
if(isset($_REQUEST["kos$a"])){$Kos = $_REQUEST["kos$a"];}

$sql_4 = "Insert Into dhmb ( NoSiriPendaftaran, Bil, Tarikh, Butiran, TempohJaminan, Kos) Values ('$NoSiriPendaftaran2', '$Bil', '$Tarikh','$Butiran','$TempohJaminan', '$Kos')"; //for error controling
$result_4=mysql_query($sql_4) or die(mysql_error());

echo ($sql_4);
}
?>


retrivehmB.php
CODE

<?php

include "dbCon.php";
$value2 =$_POST['noSiPen2'];
//need edition
$query4 = mysql_query("select * from dhmb where NoSiriPendaftaran = '$value2'");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<script language="javascript" type="text/javascript">
var v=0;
function addRowBhgnB2()
{          v++;
          frm_2.h_24.value=v;
          var tbl = document.getElementById('bhgnBHM');
          var lastRow = tbl.rows.length;
          var iteration = lastRow;
          var row = tbl.insertRow(lastRow);
      
          
           var firstCell = row.insertCell(0);
          var el6 = document.createElement('input');
          el6.type = 'text';
          el6.name = 'bil' + v;
          el6.id = 'bil' + v;
          el6.size = 10;
          el6.maxlength = 10;
          firstCell.appendChild(el6);
          
          var secondCell = row.insertCell(1);
          var el = document.createElement('input');
          el.type = 'text';
          el.name = 'tarikh' + v;
          el.id = 'tarikh' + v;
          el.size = 15;
          el.maxlength = 15;
          secondCell.appendChild(el);
          
          var thirdCell = row.insertCell(2);
          var el2 = document.createElement('input');
          el2.type = 'text';
          el2.name = 'butiran' + v;
          el2.id = 'butiran' + v;
          el2.size = 40;
          el2.maxlength = 40;
          thirdCell.appendChild(el2);

          var fourthCell = row.insertCell(3);
          var el3 = document.createElement('input');
          el3.type = 'text';
          el3.name = 'tempohJaminan' + v;
          el3.id = 'tempohJaminan' + v;
          el3.size = 25;
          el3.maxlength = 25;
          fourthCell.appendChild(el3);
          
          
          var fifthCell = row.insertCell(4);
          var el4 = document.createElement('input');
          el4.type = 'text';
          el4.name = 'kos' + v;
          el4.id = 'kos' + v;
          el4.size = 15;
          el4.maxlength = 15;
          fifthCell.appendChild(el4);
          
          var sixthCell = row.insertCell(5);
          var el5 = document.createElement('input');
          el5.type = 'text';
          el5.name = 'txtRow4' + a;
          el5.id = 'txtRow4' + a;
          el5.size = 60;
          el5.maxlength = 60;
          sixthCell.appendChild(el5);
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title></head>

<body bgcolor="#FFFFCC">
<form action="" method="post" name="frm_2" id="frm_2">
<table align="center" border="1" width="1010">
    <tr>
        <td><table align="center" border="1" width="100%" bgcolor="#FFFFFF" bordercolor="#000000">
                <tr>
                    <td colspan="4" align="right"><p><strong>KEW.PA 2</strong></p>
                          <p align="right">( No. Siri Pendaftaran:
          <label>
        
          <input name="NoSiriPendaftaran2" type="text" value="<? echo "$value2" ?>" size="20" id="NoSiriPendaftaran2">
          </label>)        </p>
                      <p align="center"><strong>DAFTAR HARTA MODAL</strong></p>
        <p align="center"><strong>BUTIR-BUTIR PENAMBAHAN, PENGGANTIAN DAN NAIKTARAF </strong></p>
        <p align="center">Bahagian B </p></td>
                </tr>
            </table>
        <table width="100%" border="1" align="center" bordercolor="#000000" bgcolor="#FFFFFF" id="bhgnBHM">    
            <tr>
                <td width="3%" align="center" bgcolor="#FFFF99">Bil.</td>
                <td width="10%" align="center" bgcolor="#FFFF99">Tarikh</td>
                <td width="25%" align="center" bgcolor="#FFFF99">Butiran</td>
                <td width="15%" align="center" bgcolor="#FFFF99">Tempoh Jaminan</td>
                <td width="10%" align="center" bgcolor="#FFFF99">Kos (RM) </td>
                <td width="37%" align="center" bgcolor="#FFFF99">Nama dan Tandatangan</td>
            </tr>
            <?php
            while ($fetch_4= mysql_fetch_assoc($query4)){
            ?>
            
            <tr>
            <td><input name="bil" type="text" value="<?php echo $fetch_4['Bil']?>"/></td>
            <td><input name="tarikh" type="text" value="<?php echo $fetch_4['Tarikh']?>"/></td>
            <td><input name="butiran" type="text" value="<?php echo $fetch_4['Butiran']?>"/></td>
            <td><input name="tempoh" type="text" value="<?php echo $fetch_4['TempohJaminan']?>"/></td>
            <td><input name="kos" type="text" value="<?php echo $fetch_4['Kos']?>"/></td>
            <td><input name="tt" type="text" /></td>
            </tr>
            <?php
            }?>
        
          </table>
          <input type="button" value="Tambah" onclick="addRowBhgnB2();" />
        </td>
    </tr>
    

<table width="100%" align="center">
<tr>
<td align="center"><input name="Submit" type="submit" value="Kemaskini" />
        <input type="hidden" name="h_24" id="h_24" /></td>
        </tr>
</table>    
</form>
</body>
</html>





thanking all of you in advance...

User is offlineProfile CardPM
+Quote Post


gregwhitworth

RE: Retrieve And Update Dynamically Added Rows

30 Jun, 2009 - 09:06 PM
Post #2

(this).problem + "sucks";
Group Icon

Joined: 20 Jan, 2009
Posts: 1,131



Thanked: 82 times
Dream Kudos: 50
Expert In: HTML, CSS, Web Design

My Contributions
I may not have understood you, but I don't see 'UPDATE' anywhere in your SQL statements. I may be wrong, but I think that that is what you are looking for.

http://www.tizag.com/mysqlTutorial/mysqlupdate.php
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:43AM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month