Breaking

Followers

Sunday, 29 March 2015

how to add dynamically multiple row with jquery and mysql in php?

I wrote about adding dynamic input fields in a webpage using  html ,jQuery, php and mysql, I got multiple of queries on how to submit it to database. This is all about generating input fields on the fly in a web page and submitting the entered data into database.  You can use this blog post to build more user friendly forms
which collect data from users. users can create fields on the fly and enter data.











<html>
<head>

<title>Untitled Document</title>
<script language="JavaScript" type="text/javascript">
  //You should create the validator only after the definition of the HTML form
  var frmvalidator  = new Validator("form1");

  frmvalidator.addValidation("eng_name","req","Please Enter Sub Page Name");
  frmvalidator.addValidation("custom_url","req","Please enter URL");

  function addRow(tableID) {
 
  var table = document.getElementById(tableID);

  var rowCount = table.rows.length;
  if(rowCount < 20){       // limit the user from creating fields more than your limits
   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;

   
     $('#dataTable tr:last .checkb:last').attr('id',rowCount);
     $('#dataTable tr:last .bed:last').attr('id','bed_'+rowCount);
     $('#dataTable tr:last .bathrooms:last').attr('id','bathrooms_'+rowCount);
     $('#dataTable tr:last .txtUnitName:last').attr('id','txtUnitName_'+rowCount);
   
     $('#dataTable tr:last .txtSize:last').attr('id','txtSize_'+rowCount);
     $('#dataTable tr:last .txtppua:last').attr('id','txtppua_'+rowCount);
     $('#dataTable tr:last .BX_tc:last').attr('id','BX_tc_'+rowCount);
   

     $('#dataTable tr:last .reset:last').val("");
   
 
 
   }
  }else{
 
     
  }
}

$("#txtppua").blur(function(){
        alert("This input field has lost its focus.");
    });
function deleteRow(tableID) {
 var table = document.getElementById(tableID);
 var rowCount = table.rows.length;
 for(var i=0; i<rowCount; i++) {
  var row = table.rows[i];
  var chkbox = row.cells[0].childNodes[0];
  if(null != chkbox && true == chkbox.checked) {
   if(rowCount <= 1) {       // limit the user from removing all the fields
    //alert("Cannot Remove all the Passenger.");
    break;
   }
   table.deleteRow(i);
   rowCount--;
   i--;
  }
 }
}


 </script>
<script language="Javascript">

      function isNumberKey(evt)
      {


         var charCode = (evt.which) ? evt.which : event.keyCode;
   if(charCode == 99 || charCode == 118)
          return true;
         if (charCode > 31 && (charCode < 46 || charCode > 57))
            return false;

         return true;
      }



  function fillUnitName(id)
  {
 
  var idValues=id;


  var arr = idValues.split('_');
  var idValue=arr[1];
  var selectValBed = $("#bed_"+idValue+" :selected").val();

  var selectValBath = $("#bathrooms_"+idValue+" :selected").val();
  var carpet_id = "txtCarpetAreaInfo_"+(idValue);
  if(selectValBed!='0' && selectValBath!='0')
  {
   var str=selectValBed+"BHK+"+selectValBath+"T";
   if($("#"+carpet_id).attr('checked'))
    var unitName=$("#txtUnitName_"+idValue).val(str+"(Carpet)");
   else
    var unitName=$("#txtUnitName_"+idValue).val(str);
  }
  }

  function TotalCost(id)
  {
 
  var idValues=id;
  var arr = idValues.split('_');
  var idValue=arr[1];
  //alert(idValues);


  var PricePerUnit=$("#txtppua_"+idValue).val();
  var txtSize=$("#txtSize_"+idValue).val();
  var total_pr=PricePerUnit*txtSize;
  $("#BX_tc_"+idValue).val(total_pr);


  }
  function show_add(id)
  {

  var idValues=id;


  var arr = idValues.split('_');
  var idValue=arr[1];

  var id = "add_"+(id+1);
  var unitName=$("#txtUnitName_"+idValue).val();
  var txtPricePerUnitArea=$("#txtPricePerUnitArea_"+idValue).val();
  var txtSize=$("#txtSize_"+idValue).val();
  var selectVal = $("#bed_"+idValue+" :selected").val();
  if(unitName !='' && txtSize!='' && selectVal!='0')
  {
   document.getElementById(id).style.display = '';
  }
  else
  {
   document.getElementById(id).style.display = 'none';
  }

  }
/*******function for deletion confirmation***********/
    function chkConfirm()
    {
        var chk = 0;
        for(var i=0;i<=30;i++) {    
            if($("#"+i).attr('checked')) {
                chk = 1;
            }
        }

        if(chk == 1)
            return confirm("Are you sure! you want to delete records which are checked.");
    }
    function add_carpet(index){

  carpet_id = "txtCarpetAreaInfo_"+(index + 1);
  unitname_id = "txtUnitName_"+(index + 1);
  unitname_val = $("#"+unitname_id).val();

  if($("#"+carpet_id).attr('checked')){
   $("#"+unitname_id).val(unitname_val+"(Carpet)");
  }else{
   unitname_val = unitname_val.replace("(Carpet)","")
   $("#"+unitname_id).val(unitname_val);
  }

 

 }

</script>
</head>

<body>

  <input onclick="addRow('dataTable')" type="button" value="Add Configuration" />

  &lt;!--    <input onclick="deleteRow('dataTable')" type="button" value="Remove Configuration" /></body></html>
<table 983px="" border="&quot;1&quot;" class="&quot;form&quot;" id="&quot;rounded-corner&quot;" important="" quot="">
  <thead>
<tr>
      <th class="&quot;rounded-company&quot;">Del</th>
      <th bbd="" class="&quot;rounded" quot="" scope="&quot;col&quot;" valign="&quot;&quot;" width="&quot;&quot;">Bedrooms</th>
      <th bbd="" class="&quot;rounded" quot="" scope="&quot;col&quot;" valign="&quot;&quot;" width="&quot;&quot;">Bathrooms</th>
      <th bbd="" class="&quot;rounded" quot="" scope="&quot;col&quot;" valign="&quot;&quot;" width="&quot;&quot;">Unit Name</th>
      <th bbdc="" class="&quot;rounded" quot="" scope="&quot;col&quot;" valign="&quot;&quot;" width="&quot;&quot;">Size</th>
      <th bbdc="" class="&quot;rounded" quot="" scope="&quot;col&quot;" valign="&quot;&quot;" width="&quot;&quot;">Price Per Unit Area</th>
      <th bbd="" class="&quot;rounded" quot="" scope="&quot;col&quot;" valign="&quot;&quot;" width="&quot;&quot;">Balcony</th>
      <th bbd="" class="&quot;rounded" quot="" scope="&quot;col&quot;" valign="&quot;&quot;" width="&quot;&quot;">Servant Room</th>
      <th bbd="" class="&quot;rounded" quot="" scope="&quot;col&quot;" valign="&quot;&quot;" width="&quot;&quot;">Pooja Room</th>
      <th bbd="" class="&quot;rounded" quot="" scope="&quot;col&quot;" valign="&quot;&quot;" width="&quot;&quot;">Study Room</th>
      <th bbdc="" class="&quot;rounded" quot="" scope="&quot;col&quot;" valign="&quot;&quot;" width="&quot;&quot;">Total Cost</th>
      <th bbdcd="" class="&quot;rounded-q4" quot="">Floor Plan</th>
    </tr>
</thead>
</table>
<table border="&quot;1&quot;" class="&quot;form&quot;" id="&quot;dataTable&quot;">
  <tbody>
<tr>
   
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><a 6px="" class="&quot;ask&quot;" href="https://www.blogger.com/%22configuration_pages_manage.php?property_id=11&amp;del_id=365%22" quot=""><img border="&quot;0&quot;" src="&quot;OBERNDEV.COM/images/trash.png&quot;" /></a>
        <input class="&quot;checkb" id="&quot;1&quot;" name="&quot;chk[]&quot;" none="" quot="" reset="" type="&quot;checkbox&quot;" />
        <input class="&quot;checkb" name="&quot;c_id[]&quot;" quot="" reset="" type="&quot;hidden&quot;" value="&quot;365&quot;" /></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 67px="" class="&quot;bed" fillunitname="" id="&quot;bed_0&quot;" name="&quot;BX_Bedrooms[]&quot;" onchange="&quot;show_add(this.id);" quot="" reset="" tempname="&quot;bed&quot;" this.id="">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option value="&quot;2&quot;">2</option>
          <option value="&quot;3&quot;">3</option>
          <option selected="&quot;selected&quot;" value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 71px="" class="&quot;bathrooms" id="&quot;bathrooms_0&quot;" name="&quot;BX_Bathrooms[]&quot;" onchange="&quot;fillUnitName(this.id);&quot;" quot="" reset="" tempname="&quot;bathrooms&quot;">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option value="&quot;2&quot;">2</option>
          <option value="&quot;3&quot;">3</option>
          <option selected="&quot;selected&quot;" value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><input 57px="" class="&quot;small" id="&quot;txtUnitName_0&quot;" name="&quot;BX_Unit_Name[]&quot;" onblur="&quot;show_add(this.id);&quot;" quot="" required="&quot;required&quot;" reset="" txtunitname="" type="&quot;text&quot;" value="&quot;3BHK+4T&quot;" /></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><input 55px="" class="&quot;small" event="" id="&quot;txtSize_0&quot;" isnumberkey="" name="&quot;BX_Size[]&quot;" onblur="&quot;TotalCost(this.id);&quot;" onkeypress="&quot;return" quot="" required="&quot;required&quot;" reset="" txtsize="" type="&quot;text&quot;" value="&quot;23&quot;" /></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><input 60px="" class="&quot;small" id="&quot;txtppua_0&quot;" name="&quot;BX_ppua[]&quot;" onblur="&quot;TotalCost(this.id)&quot;" quot="" required="&quot;required&quot;" reset="" txtppua="" type="&quot;text&quot;" value="&quot;4000&quot;" /></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 60px="" class="&quot;BX_bsr" id="&quot;BX_bsr&quot;" name="&quot;BX_bsr[]&quot;" quot="" reset="" tempname="&quot;BX_bsr&quot;">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option value="&quot;2&quot;">2</option>
          <option selected="&quot;selected&quot;" value="&quot;3&quot;">3</option>
          <option value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 61px="" class="&quot;BX_svr" id="&quot;BX_svr&quot;" name="&quot;BX_svr[]&quot;" quot="" reset="" tempname="&quot;BX_svr&quot;">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option value="&quot;2&quot;">2</option>
          <option selected="&quot;selected&quot;" value="&quot;3&quot;">3</option>
          <option value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 61px="" class="&quot;BX_pr" id="&quot;BX_pr&quot;" name="&quot;BX_pr[]&quot;" quot="" reset="" tempname="&quot;BX_pr">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option value="&quot;2&quot;">2</option>
          <option selected="&quot;selected&quot;" value="&quot;3&quot;">3</option>
          <option value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 61px="" class="&quot;BX_fpt" id="&quot;BX_fpt&quot;" name="&quot;BX_fpt[]&quot;" quot="" reset="" tempname="&quot;BX_fpt&quot;">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option value="&quot;2&quot;">2</option>
          <option selected="&quot;selected&quot;" value="&quot;3&quot;">3</option>
          <option value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><input 60px="" bx_tc="" class="&quot;small" id="&quot;BX_tc_0&quot;" name="&quot;BX_tc[]&quot;" quot="" required="&quot;required&quot;" reset="" type="&quot;text&quot;" value="&quot;92000&quot;" /></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><a class="&quot;highslide&quot;" href="https://www.blogger.com/%22OBERNDEV.COM/cfp/11_564_a.jpeg%22" hs.expand="" onclick="&quot;return" quot="" this=""><img align="&quot;absmiddle&quot;" src="&quot;OBERNDEV.COM/images/camera.png&quot;" /></a>
        <input class="&quot;txtbox" name="&quot;image[]&quot;" quot="" reset="" type="&quot;file&quot;" value="&quot;11_564_a.jpeg&quot;" />
        &nbsp;
        <!--  <input type=checkbox name=image_del value=&quot;1&quot; >
          Delete Image--></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"></td>
        <br />

    </tr>
<tr>
   
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><a 6px="" class="&quot;ask&quot;" href="https://www.blogger.com/%22configuration_pages_manage.php?property_id=11&amp;del_id=368%22" quot=""><img border="&quot;0&quot;" src="&quot;OBERNDEV.COM/images/trash.png&quot;" /></a>
        <input class="&quot;checkb" id="&quot;1&quot;" name="&quot;chk[]&quot;" none="" quot="" reset="" type="&quot;checkbox&quot;" />
        <input class="&quot;checkb" name="&quot;c_id[]&quot;" quot="" reset="" type="&quot;hidden&quot;" value="&quot;368&quot;" /></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 67px="" class="&quot;bed" fillunitname="" id="&quot;bed_1&quot;" name="&quot;BX_Bedrooms[]&quot;" onchange="&quot;show_add(this.id);" quot="" reset="" tempname="&quot;bed&quot;" this.id="">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option value="&quot;2&quot;">2</option>
          <option value="&quot;3&quot;">3</option>
          <option selected="&quot;selected&quot;" value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 71px="" class="&quot;bathrooms" id="&quot;bathrooms_1&quot;" name="&quot;BX_Bathrooms[]&quot;" onchange="&quot;fillUnitName(this.id);&quot;" quot="" reset="" tempname="&quot;bathrooms&quot;">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option value="&quot;2&quot;">2</option>
          <option value="&quot;3&quot;">3</option>
          <option selected="&quot;selected&quot;" value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><input 57px="" class="&quot;small" id="&quot;txtUnitName_1&quot;" name="&quot;BX_Unit_Name[]&quot;" onblur="&quot;show_add(this.id);&quot;" quot="" required="&quot;required&quot;" reset="" txtunitname="" type="&quot;text&quot;" value="&quot;4BHK+4T&quot;" /></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><input 55px="" class="&quot;small" event="" id="&quot;txtSize_1&quot;" isnumberkey="" name="&quot;BX_Size[]&quot;" onblur="&quot;TotalCost(this.id);&quot;" onkeypress="&quot;return" quot="" required="&quot;required&quot;" reset="" txtsize="" type="&quot;text&quot;" value="&quot;5000&quot;" /></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><input 60px="" class="&quot;small" id="&quot;txtppua_1&quot;" name="&quot;BX_ppua[]&quot;" onblur="&quot;TotalCost(this.id)&quot;" quot="" required="&quot;required&quot;" reset="" txtppua="" type="&quot;text&quot;" value="&quot;234&quot;" /></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 60px="" class="&quot;BX_bsr" id="&quot;BX_bsr&quot;" name="&quot;BX_bsr[]&quot;" quot="" reset="" tempname="&quot;BX_bsr&quot;">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option value="&quot;2&quot;">2</option>
          <option value="&quot;3&quot;">3</option>
          <option selected="&quot;selected&quot;" value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 61px="" class="&quot;BX_svr" id="&quot;BX_svr&quot;" name="&quot;BX_svr[]&quot;" quot="" reset="" tempname="&quot;BX_svr&quot;">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option value="&quot;2&quot;">2</option>
          <option selected="&quot;selected&quot;" value="&quot;3&quot;">3</option>
          <option value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 61px="" class="&quot;BX_pr" id="&quot;BX_pr&quot;" name="&quot;BX_pr[]&quot;" quot="" reset="" tempname="&quot;BX_pr">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option selected="&quot;selected&quot;" value="&quot;2&quot;">2</option>
          <option value="&quot;3&quot;">3</option>
          <option value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><select 61px="" class="&quot;BX_fpt" id="&quot;BX_fpt&quot;" name="&quot;BX_fpt[]&quot;" quot="" reset="" tempname="&quot;BX_fpt&quot;">
          <option value="&quot;0&quot;">Select</option>
          <option value="&quot;1&quot;">1</option>
          <option selected="&quot;selected&quot;" value="&quot;2&quot;">2</option>
          <option value="&quot;3&quot;">3</option>
          <option value="&quot;4&quot;">4</option>
          <option value="&quot;5&quot;">5</option>
          <option value="&quot;6&quot;">6</option>
          <option value="&quot;7&quot;">7</option>
          <option value="&quot;8&quot;">8</option>
          <option value="&quot;9&quot;">9</option>
          <option value="&quot;10&quot;">10</option>
        </select></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><input 60px="" bx_tc="" class="&quot;small" id="&quot;BX_tc_1&quot;" name="&quot;BX_tc[]&quot;" quot="" required="&quot;required&quot;" reset="" type="&quot;text&quot;" value="&quot;1170000&quot;" /></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"><a class="&quot;highslide&quot;" href="https://www.blogger.com/%22OBERNDEV.COM/cfp/11_380_a.jpeg%22" hs.expand="" onclick="&quot;return" quot="" this=""><img align="&quot;absmiddle&quot;" src="&quot;OBERNDEV.COM/images/camera.png&quot;" /></a>
        <input class="&quot;txtbox" name="&quot;image[]&quot;" quot="" reset="" type="&quot;file&quot;" value="&quot;11_380_a.jpeg&quot;" />
        &nbsp;
        <!--  <input type=checkbox name=image_del value=&quot;1&quot; >
          Delete Image--></td>
      <td align="&quot;&quot;" valign="&quot;middle&quot;" width="&quot;500&quot;"></td>
        <br />

    </tr>
</tbody>
</table>
<table>
<tr>
    <td><div 200px="" quot="">
        <input class="&quot;form_submit&quot;" id="&quot;submit&quot;" name="&quot;Submit&quot;" type="&quot;submit&quot;" value="&quot;Update&quot;" />
        &nbsp; <a 0="" 1px="" 2="" 53px="" 7px="" 8px="" bold="" border:="" button.gif="" color:="" font-weight:="" height:="" href="https://www.blogger.com/%22OBERNDEV.COM?property_id=11%22" img="" margin:="" padding:="" quot="" solid="" url="" white="">Next</a> </div>
</td></tr>
</table>

</body>
</html>


--------------------------------------------------------------------------------------------------------------------------

<?php
class infoPage
{
 public $c_id   = array();
 public $property_id  = '';
 public $BX_Bedrooms    = array();
 public $BX_Bathrooms = array();
 public $BX_Unit_Name = array();
 public $BX_Size        = array();
 public $BX_ppua        = array();
 public $BX_bsr        = array();
 public $BX_svr        = array();
 public $BX_pr        = array();
 public $BX_fpt        = array();
 public $BX_tc        = array();
 //public $BX_flpn        = array();
 public $get_data        = array();

 
 public $edit_id    = '';
 public $formTitle  = 'Create';
 public $buttonName = "Create";
 public $action_value  = "";
 
 
 public $objImage       = NULL;
 public $imgPath       = '';
 public $image         = array();
 public $image_del        = array();
 
 function __construct()
 {
  $this->imgPath  = C_SITE_PATH."/".C_CFP_IMAGE."/";
 }
 function setImageObject($objImg = NULL)
 {
  $this->objImage = $objImg;
 }
function getPostValue()
{
  if(isset($_POST['BX_Bedrooms']))
   $this->BX_Bedrooms = $_POST['BX_Bedrooms'];
 if(isset($_POST['property_id']))
   $this->property_id = $_POST['property_id'];
   
  if(isset($_POST['BX_Bathrooms']))
   $this->BX_Bathrooms = $_POST['BX_Bathrooms'];
  
  if(isset($_POST['BX_Unit_Name']))
   $this->BX_Unit_Name = $_POST['BX_Unit_Name'];
  
  if(isset($_POST['BX_Size']))
   $this->BX_Size = $_POST['BX_Size'];
  
  if(isset($_POST['BX_ppua']))
   $this->BX_ppua = $_POST['BX_ppua'];
  
  if(isset($_POST['BX_bsr']))
   $this->BX_bsr = $_POST['BX_bsr'];
  
  if(isset($_POST['BX_svr']))
   $this->BX_svr = $_POST['BX_svr'];
  
  if(isset($_POST['BX_pr']))
   $this->BX_pr = $_POST['BX_pr'];
  
  if(isset($_POST['BX_fpt']))
   $this->BX_fpt = $_POST['BX_fpt'];
  
  if(isset($_POST['BX_tc']))
   $this->BX_tc = $_POST['BX_tc'];
  
  /*if(isset($_POST['BX_flpn']))
   $this->BX_flpn = $_POST['BX_flpn'];*/
   
  if(isset($_POST['c_id']))
   $this->c_id = $_POST['c_id'];
     
  if(isset($_POST['edit_id']))
   $this->edit_id = $_POST['edit_id'];
  
  if(isset($_POST['action_value']))
   $this->action_value = $_POST['action_value'];
   
   
   // images
  if(isset($_FILES['image']))
  {
   $this->image = $_FILES['image'];
  }
  
  if(isset($_POST['image_del']))
  {
   $this->image_del = $_REQUEST['image_del'];
  }
 }
 
function empty_form()
{
  $this->c_id     = array();
  $this->BX_Bedrooms        = array();
  $this->BX_Bathrooms        = array();
  $this->BX_Unit_Name        = array();
  $this->BX_Size         = array();
  $this->BX_ppua         = array();
  $this->BX_bsr         = array();
  $this->BX_svr         = array();
  $this->BX_pr         = array();
  $this->BX_fpt         = array();
  $this->BX_tc         = array();
  //$this->BX_flpn         = array();
  $this->get_data         = array();
  $this->edit_id     = '';
  $this->image        = array();
 }

function getDetails($id)
{
  if(!empty($id))
  {
   $sql = "Select * from T_PROPERTY_CONFIGURATION where property_id='".$id."'";
   $result = mysql_query($sql);
   if($result)
   {
    while($query = mysql_fetch_array($result))
    {
     $this->get_data[]=array(
     
     'c_id'    => stripslashes($query['id']),
     'BX_Bedrooms'   => stripslashes($query['BX_Bedrooms']),
     'BX_Bathrooms'   => stripslashes($query['BX_Bathrooms']),
     'BX_Unit_Name'    => stripslashes($query['BX_Unit_Name']),
     'BX_Size'         => stripslashes($query['BX_Size']),
     'BX_ppua'        => stripslashes($query['BX_ppua']),
     'BX_bsr'    => stripslashes($query['BX_bsr']),
     'BX_svr'     => stripslashes($query['BX_svr']),
     'BX_pr'         => stripslashes($query['BX_pr']),
     'BX_fpt'     => stripslashes($query['BX_fpt']),
     'BX_tc'      => stripslashes($query['BX_tc']),
     'image'       => stripslashes($query['BX_flpn']),
     'property_id'   => $query['property_id']);
    }
    return $this->get_data;
   }
  }
 }
function isDuplicate($id = '')
{
  $sqlStmt = "Select * from T_PROPERTY_CONFIGURATION where  id='".$id."' ";
  
  $result = mysql_query($sqlStmt);
  if($result)
  {
   $num = mysql_num_rows($result);
   
   return $num;
  }
 }
 

function add()
 {
  
   $insertId='';
   
   $i=0;
   foreach($this->BX_Bedrooms as $a => $b){
    
    $this->objImage->image_tmp_name = $this->image['tmp_name'][$a];
    $this->objImage->processImage();
    $image_type   = $this->objImage->getImageType();
    $img_name  = $this->property_id.'_'.rand('1,100').'_a.'.$image_type;
    $targetPath  = $this->imgPath.$img_name;
    $ret    = $this->objImage->saveImage($targetPath, 1);
    //$img_name   = $this->objImage->saveBMP2JPG($this->imgPath,$img_name);   

    $sqlStmt  = "Insert into T_PROPERTY_CONFIGURATION Set ";
    $sqlStmt  .= "  BX_Bedrooms     = '".$this->BX_Bedrooms[$a]."',
        property_id    = '".$this->property_id."',
        BX_Bathrooms    = '".$this->BX_Bathrooms[$a]."',
        BX_Unit_Name    = '".$this->BX_Unit_Name[$a]."',
        BX_Size        = '".$this->BX_Size[$a]."',
        BX_ppua        = '".$this->BX_ppua[$a]."',
        BX_bsr        = '".$this->BX_bsr[$a]."',
        BX_svr       = '".$this->BX_svr[$a]."',
        BX_pr      = '".$this->BX_pr[$a]."',
        BX_fpt      = '".$this->BX_fpt[$a]."',
        BX_tc      = '".$this->BX_tc[$a]."',
        BX_flpn      = '".$img_name."'";
        
        if(mysql_query($sqlStmt))
        {
          $insertId = mysql_insert_id();

        
        }
   
  }
  return $insertId;
  
  
 }
 
function edit()
 {
   
   $i=0;
  
   foreach($this->BX_Bedrooms as $a => $b){
    $tmp_name=$this->image['tmp_name'][$a];
   
    if($this->isDuplicate($this->c_id[$a])>0)
    {
    
       if(!empty($tmp_name))
       {
        $this->saveImage($this->c_id[$a],$tmp_name);
       }   

       $sqlStmt  = "Update  T_PROPERTY_CONFIGURATION Set ";
       $sqlStmt  .= "  BX_Bedrooms     = '".$this->BX_Bedrooms[$a]."',
        property_id    = '".$this->property_id."',
        BX_Bathrooms    = '".$this->BX_Bathrooms[$a]."',
        BX_Unit_Name    = '".$this->BX_Unit_Name[$a]."',
        BX_Size        = '".$this->BX_Size[$a]."',
        BX_ppua        = '".$this->BX_ppua[$a]."',
        BX_bsr        = '".$this->BX_bsr[$a]."',
        BX_svr       = '".$this->BX_svr[$a]."',
        BX_pr      = '".$this->BX_pr[$a]."',
        BX_fpt      = '".$this->BX_fpt[$a]."',
        BX_tc      = '".$this->BX_tc[$a]."'";
        $sqlStmt .= " where id='".$this->c_id[$a]."'";
        if(mysql_query($sqlStmt))
        {
          $insertId = mysql_insert_id();

        }
    }
    else{
     echo $this->isDuplicate($this->c_id[$a]);
     
     $sqlStmt  = "Insert into T_PROPERTY_CONFIGURATION Set ";
       $sqlStmt  .= "  BX_Bedrooms     = '".$this->BX_Bedrooms[$a]."',
        property_id    = '".$this->property_id."',
        BX_Bathrooms    = '".$this->BX_Bathrooms[$a]."',
        BX_Unit_Name    = '".$this->BX_Unit_Name[$a]."',
        BX_Size        = '".$this->BX_Size[$a]."',
        BX_ppua        = '".$this->BX_ppua[$a]."',
        BX_bsr        = '".$this->BX_bsr[$a]."',
        BX_svr       = '".$this->BX_svr[$a]."',
        BX_pr      = '".$this->BX_pr[$a]."',
        BX_fpt      = '".$this->BX_fpt[$a]."',
        BX_tc      = '".$this->BX_tc[$a]."'";
        
        if(mysql_query($sqlStmt))
        {
          echo $insertId = mysql_insert_id();
          $this->saveImage($insertId,$tmp_name);
          echo $tmp_name;

        }
     
     }
   }
 }
function saveImage($insertId,$tmp_name)
 {
  if(!empty($tmp_name))
  {  
   /*Inserting Image*/ 
   $this->objImage->image_tmp_name = $tmp_name;
   $this->objImage->processImage();
   $image_type   = $this->objImage->getImageType();
   $img_name  = $this->property_id.'_'.rand(200,1000).'_a.'.$image_type;
   $targetPath  = $this->imgPath.$img_name;
   $ret    = $this->objImage->saveImage($targetPath, 1);
   if($ret)
   {
     
    $qry1=mysql_query("Update T_PROPERTY_CONFIGURATION Set BX_flpn='".$img_name."' where id='".$insertId."'");
   }
   else
   {
    $this->errorList = $this->objImage->img_error;
   }
  }
 }
 function deleteImage($id)
 {
  $this->deleteSingleImage('BX_flpn', $this->imgPath, $id);
 }
 function deleteSingleImage($fld, $dir, $id)
 {
  if(!empty($fld) && !empty($dir) && !empty($id))
  {
   $sql2    = "Select ".$fld." from T_PROPERTY_CONFIGURATION where property_id='".$id."'";
   $result2 = mysql_query($sql2);
   if($result2)
   {     
    while($query2 = mysql_fetch_array($result2))
    {
     $img_name    = $query2[$fld];
     $targetPath  = $dir.$img_name;
     
     if(file_exists($targetPath) && !empty($img_name))
     { 
      unlink($targetPath);
     }
    }
   }
   
   $qry1 = mysql_query("Update T_PROPERTY Set ".$fld."='' where property_id='".$id."'");
  }
 } 
 
 function deleteImagerow($id)
 {
  $this->deleteSingleImagerow('BX_flpn', $this->imgPath, $id);
 }
 function deleteSingleImagerow($fld, $dir, $id)
 {
  if(!empty($fld) && !empty($dir) && !empty($id))
  {
   $sql2    = "Select ".$fld." from T_PROPERTY_CONFIGURATION where id='".$id."'";
   $result2 = mysql_query($sql2);
   if($result2)
   {     
    while($query2 = mysql_fetch_array($result2))
    {
     $img_name    = $query2[$fld];
     $targetPath  = $dir.$img_name;
     
     if(file_exists($targetPath) && !empty($img_name))
     { 
      unlink($targetPath);
     }
    }
   }
   
   $qry1 = mysql_query("Update T_PROPERTY Set ".$fld."='' where property_id='".$id."'");
  }
 } 
function delete($id)
 {
  $this->deleteImage($id);
  $sql2 = "Delete from T_PROPERTY_CONFIGURATION where property_id='".$id."'";
  
  if(!mysql_query($sql2))
  {
   $this->msg = "Problem to delete data, please try again !!! Error: ". mysql_error();
  }
 }

function deleterow($id)
 {
  $this->deleteImagerow($id);
  $sql2 = "Delete from T_PROPERTY_CONFIGURATION where id='".$id."'";
  
  if(!mysql_query($sql2))
  {
   $this->msg = "Problem to delete data, please try again !!! Error: ". mysql_error();
  }
 }
 
}
?>

No comments:

Post a Comment