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