Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript PHP
Hi friends,
 
I am struggling for few days for this issue.
 
In my appication, I have taken one button for adding row, so when I click addrow button row added successfully.
If click multiple times, multiple rows also added.
In added row, I have taken one dropdown box and one text box.
In drop down, I have some items coming from database.
Whenever I select one item, based on that selected item populating value in textbox. So, whenever I try to update multiple rows, that updating rows are not working.
Only first row is updating and the remaining rows are not updated.
 
Mycode is here.
<?php
?>
<SCRIPT language="javascript">
 
        function addRow(tableID) {
 
            var table = document.getElementById(tableID);
 
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
 
            var colCount = table.rows[0].cells.length;
 
            for(var i=0; i<colCount; i++) {
 
                var newcell = row.insertCell(i);
 
                newcell.innerHTML = table.rows[0].cells[i].innerHTML;
                //alert(newcell.childNodes);
                switch(newcell.childNodes[0].type) {
                    case "text":
                            newcell.childNodes[0].value = "";
                            break;
                    case "checkbox":
                            newcell.childNodes[0].checked = false;
                            break;
                    case "select-one":
                            newcell.childNodes[0].selectedIndex = 0;
                            break;
                }
            }
        }
        </script>
 
<script>
        if (window.XMLHttpRequest)
        {
              xmlhttp=new XMLHttpRequest();
 
        }
        else
        {
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
 
        function validateform2(x)
        {
              //alert(x)
              xmlhttp.onreadystatechange=function()
              {
                  if (xmlhttp.readyState==4 && xmlhttp.status==200)
                  {
                document.getElementById("tax").value=xmlhttp.responseText;
                      //alert(tax);
                  }
              }
 
              xmlhttp.open("POST","state-tax.php",true);
              xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
              xmlhttp.send("key="+x);
        }
</script>
 
<form name="retire" action="state-apportionment-busd.php" method="POST">
<table border="0" align="left" width="100%" bgcolor="#d6eafb" cellpadding="8" cellspacing="1">
<tbody><tr>
<td width="14%" align="center" valign="top" class="tbl-area-tabs"><strong> Business Name</strong></td>
<td width="14%" align="center" valign="top" class="tbl-area-tabs"><strong> Tax ID Employer ID</strong></td>
</tr></table>
 
<table border="0" align="left" width="100%" bgcolor="#d6eafb" cellpadding="8" cellspacing="1">
<?php
 
$lu=$_COOKIE['lu'];//login user id
$sql="select * from state_apportionment where user_id=$lu";
 

//echo $sql;
$result=mysql_query($sql) or die("Query failed $sql".mysql_error());
 

 
while($row=mysql_fetch_array($result))
{
?>
<tr bgcolor="#FFFFFF">
 
<td width="14%" align="left" valign="top"  style="margin:0px auto;">
<select name="textfield1[]" class="select-box-new" id="state-one" onchange="return validateform2(this.value)">
<option value="">select</option>
<?php
$sql=mysql_query("select basic_name from business_profile where user_id=$lu");
while($result=mysql_fetch_array($sql))
{
?>
<option value="<?php echo $result['basic_name'];?>" <?php if($row['textfield1']==$result['basic_name']){?> selected="selected" <?php } ?>><?php echo $result['basic_name']; ?></option>
<?php
}
?>
 

 

 
</select></td>
 

 

 
<td width="14%" align="left" valign="top" style="margin:0px auto;">
<input name="textfield2[]" type="text" id="tax" size="8" value="<?php echo $row['textfield2']; ?>"/>
</td>
<?php } ?>
 

 

<table border="0" align="left" width="100%" bgcolor="#d6eafb" cellpadding="8" cellspacing="1" id="dataTable">
<tr>
 

 
<td width="14%" align="left" valign="top" style="margin:0px auto;">
<select name="textfield1[]" class="select-box-new" id="textfield1" id="state-one" onchange="return validateform2(this.value)">
<option value="">select</option>
<?php
$sql=mysql_query("select basic_name from business_profile where user_id=$lu");
while($result=mysql_fetch_array($sql))
{
?>
<option value="<?php echo $result['basic_name'];?>" <?php if($row['textfield1']==$result['basic_name']){?> selected="selected" <?php } ?>><?php echo $result['basic_name']; ?></option>
<?php
}
?>
</select></td>
 

<td width="14%" align="left" valign="top" style="margin:0px auto;">
<input name="textfield2[]" type="text" id="tax" size="8" /></td>
 

 
<br><INPUT type="button" value="Add Row" onClick="addRow('dataTable')" />
 
</table>
 
</table>
<table align="center">
<tr>
<td align="right" valign="middle"><input type="submit" name="submit" value="Save">
</td>
</tr>
</table>
</form>
 

 
//state-apportionment-busd.php
 
<?php
include "db.php";
 

$lu=$_COOKIE['lu'];
//echo "cookie".$_COOKIE['lu'];
extract($_POST);
 
$textfield1 = $_POST['textfield1'];
$textfield2 = $_POST['textfield2'];
 

//print_r($_POST);
//echo "<pre>";
//die();

$search_r1=mysql_query("select user_id from state_apportionment_total where user_id=".$lu);
$sql1="select * from state_apportionment  where user_id=$lu";
 
//echo $sql;
$result1=mysql_query($sql1) or die("Query failed $sql1".mysql_error());
 
if(mysql_num_rows($result1)!=0)
{
$sql1="DELETE FROM state_apportionment WHERE user_id=$lu";
$result1=mysql_query($sql1) or die("Query failed $sql1".mysql_error());
}
foreach($textfield1 as $a => $b)
    {
 
$sql="INSERT INTO state_apportionment  VALUES('',$lu,'$textfield1[$a]','$textfield2[$a]')";
 
//echo $sql;
$result=mysql_query($sql) or die("Query failed $sql".mysql_error());
 

}
 

 

/*else
{
        foreach($textfield1 as $a => $b)
    {
    $sql2="UPDATE retirement_expenses SET textfield1='$textfield1[$a]',textfield2='$textfield2[$a]' where user_id=$lu ";
 
//echo $sql2;
$result2=mysql_query($sql2) or die("Query failed $sql2".mysql_error());
 
    }}
 */
?>
 
<script>parent.location='somepage.php?data=update'; </script>
 
Please give solution.
 

Thanks & Regards
 
Mallesh
Email Removed
 
[Edit]
1. Email removed.
2. Grammatical errors corrected.
[/Edit]
Posted 10-Feb-13 5:09am
Edited 10-Feb-13 6:30am
(no name)114.5K
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 515
1 Maciej Los 340
2 Richard MacCutchan 265
3 BillWoodruff 225
4 Mathew Soji 155
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 10 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100