473,569 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updation in database using Ajax

190 New Member
i have 2 tables bank master and branch details having bankcode as a common feild .

i have designed a form in which i am filtering branches according to a particular bank code using ajax , i an fine till this ..... now i want that fields of these records should come in a separate field so that i can change my data there itselfe and using ajax can update database on onblur event ...... how to do this ?

this is my code for displaying information about banches having similar bank_code
[PHP]elseif($name == "select_bank_co de")
{
$sql="SELECT * FROM bankbranches WHERE bank_code = '".$q."'";
$result = mysql_query($sq l);
echo "<table width='100%'>";
$i=0;
while($row = mysql_fetch_arr ay($result))
{
$bcode = $row['bank_code'] ;
$brcode = $row['branch_code'] ;
$badd = $row['branch_address '] ;
$pin = $row['branch_address '] ;
$bc = "bank_code" ;

echo "<input name='branch_co de[$i]' type='hidden' value='$row[branch_code]'/>";
echo "<tr><td>Ba nk Code </td><td><input type='text' name='bcode[$i]' value='".$bcode ."' onblur='modufy_ rec('".$bcode." ','".$brcode."' ,this.value,'ba nk_code');'></td>";
echo "<tr><td>Br anch Code </td><td><input type='text' name='brcode[$i]' value='".$brcod e."' onblur='modufy_ rec('".$bcode." ','".$brcode."' ,this.value,'br anch_code');'></td>";
echo "<tr><td>Br anch address </td><td><input type='text' name='baddress[$i]' value='".$badd. "' onblur='modufy_ rec('".$bcode." ','".$brcode."' ,this.value,'br anch_address'); '></td>";
echo "<tr><td>Pincod e </td><td><input type='text' name='pincode[$i]' value='".$pin." ' onblur='modufy_ rec('".$bcode." ','".$brcode."' ,this.value,'pi ncode');'></td>";

$i+1;
}
echo "</table>";


}[/PHP]

Using this i am getting values displayed but onblur is not working , this fuction takes necessary fields for generating query and this is javascript function which calls PHP ultimatly
Jun 3 '08 #1
17 2924
acoder
16,027 Recognized Expert Moderator MVP
You seem to have mixed quotes. If you look at the generated source, you should see the problem. Also look at error messages that you may see in the error console.
Jun 3 '08 #2
Shalini Bhalla
190 New Member
I have 2 tables bank master and branch details having common fields bank_code

using Ajax i am displaying branch details of a particular bank_code in a dynamic form in texbox so that if i want to make any change i can change and save it using ajax on onblur event of textbox in which i have made changes ..

I have successfully completed till displaying values in text box , but now i want to save Changes where my ajax function is not executing....

code for displaying dynamic for is :

[PHP]elseif($name == "select_bank_co de")
{
$sql="SELECT * FROM bankbranches WHERE bank_code = '".$q."'";
$result = mysql_query($sq l);

echo "<form name='form2'><t able width='100%'>";
$i=0;
while($row = mysql_fetch_arr ay($result))
{
$bcode = $row['bank_code'] ;
$brcode = $row['branch_code'] ;
$badd = $row['branch_address '] ;
$pin = $row['pincode'] ;
$bc = "bank_code" ;
$br = "branch_cod e";
$bad = "beanch_address ";
$pc = "Pincode";

echo "<tr><input name='branch_co de[\'".$i."]\' type='hidden' value='$row[branch_code]'/>";
echo "<td>Bank Code </td><td><input type=\"text\" name=\"bcode{$i }\" value=\" {$bcode}\" onblur=\"modify _rec('{$bcode}' , '{$brcode}', this.value,'{$b c}')\" /></td>";
echo "<td>Branch Code </td><td><input type=\"text\" name=\"brcode{$ i}\" value=\" {$brcode}\" onblur=\"modify _rec('{$bcode}' , '{$brcode}', this.value,'{$b r}')\" /></td>";
echo "<td>Branch Address </td><td><input type=\"text\" name=\"badd{$i} \" value=\" {$badd}\" onblur=\"modify _rec('{$bcode}' , '{$brcode}', this.value,'{$b ad}')\" /></td>";
echo "<td>Pin</td><td><input type=\"text\" name=\"pin{$i}\ " value=\" {$badd}\" onblur=\"modify _rec('{$bcode}' , '{$brcode}', this.value,'{$p c}')\" /></td>";
$i+1;
}
echo "</table></form>";
[/PHP]


and code for Aajax is :


[HTML]<script>


function modify_rec(bcod e,brcode,val,nm )
{

var ajaxRequest; // The variable that makes Ajax possible!

try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest( );
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject(" Msxml2.XMLHTTP" );
} catch (e) {
try{
ajaxRequest = new ActiveXObject(" Microsoft.XMLHT TP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onr eadystatechange = function(){
alert("fsdsf12" );
if(ajaxRequest. readyState == 4){
document.form2. time.value = ajaxRequest.res ponseText;
}
}
alert("fsdsf13" );
url=url+"?bcode =" + bcode + "&brcode=" + brcode + "&fnm=" + nm + "&val=" + val;
alert(url);
ajaxRequest.ope n("GET", "modify_branche s.php" + url , true);
ajaxRequest.sen d(null);
}
</script>[/HTML]


when i am calling modify_rec()

using alert i can see that values have been passed in function but when i am trying to alert url from modify_rec() nothing have been printed ....

can anbody solve the problem
Jun 5 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Merged threads since it relates to the same problem (title).

Show the generated source as the HTML appears on the client-side in your browser (View Source).
Jun 5 '08 #4
Shalini Bhalla
190 New Member
i am not understanding exactly what you want to know ?
Jun 5 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
OK, I'll try again. Can you see this part:
[PHP]echo "<tr><input name='branch_co de[\'".$i."]\' type='hidden' value='$row[branch_code]'/>";
echo "<td>Bank Code </td><td><input type=\"text\" name=\"bcode{$i }\" value=\" {$bcode}\" onblur=\"modify _rec('{$bcode}' , '{$brcode}', this.value,'{$b c}')\" /></td>";
echo "<td>Branch Code </td><td><input type=\"text\" name=\"brcode{$ i}\" value=\" {$brcode}\" onblur=\"modify _rec('{$bcode}' , '{$brcode}', this.value,'{$b r}')\" /></td>";
echo "<td>Branch Address </td><td><input type=\"text\" name=\"badd{$i} \" value=\" {$badd}\" onblur=\"modify _rec('{$bcode}' , '{$brcode}', this.value,'{$b ad}')\" /></td>";
echo "<td>Pin</td><td><input type=\"text\" name=\"pin{$i}\ " value=\" {$badd}\" onblur=\"modify _rec('{$bcode}' , '{$brcode}', this.value,'{$p c}')\" /></td>";[/PHP] That's PHP which I can understand, but I'd rather see the HTML. If you load the page in your browser and then in the browser menu select View -> Source (or Page Source). This will show you the HTML code as rendered in the browser. Find the form/table code and post that here.
Jun 5 '08 #6
Shalini Bhalla
190 New Member
This is the code vhich i am getting after executing ajax first time

[HTML]



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>BANK BRABCH DETAILS</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style1.cs s" rel="stylesheet " type="text/css">
<script>


var xmlHttp

function showUser(str , nm)
{


xmlHttp=GetXmlH ttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="get_bank_b ranch_code.php" ;
url=url+"?q="+s tr+"&name="+nm ;
url=url+"&sid=" +Math.random()
xmlHttp.onready statechange=sta teChanged
xmlHttp.open("G ET",url,true)
xmlHttp.send(nu ll)
}


function stateChanged()
{
if (xmlHttp.readyS tate==4 || xmlHttp.readySt ate=="complete" )
{
document.getEle mentById("txtHi nt").innerHTML= xmlHttp.respons eText
}
}

function GetXmlHttpObjec t()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest( );
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject(" Msxml2.XMLHTTP" );
}
catch (e)
{
xmlHttp=new ActiveXObject(" Microsoft.XMLHT TP");
}
}
return xmlHttp;
}

</script>

<script>


function modify_rec(bcod e,brcode,val,nm )
{

var ajaxRequest; // The variable that makes Ajax possible!

try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest( );
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject(" Msxml2.XMLHTTP" );
} catch (e) {
try{
ajaxRequest = new ActiveXObject(" Microsoft.XMLHT TP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onr eadystatechange = function(){
alert("fsdsf12" );
if(ajaxRequest. readyState == 4){
document.form2. time.value = ajaxRequest.res ponseText;
}
}
alert("fsdsf13" );
url=url+"?bcode =" + bcode + "&brcode=" + brcode + "&fnm=" + nm + "&val=" + val;
alert(url);
ajaxRequest.ope n("GET", "modify_branche s.php" + url , true);
ajaxRequest.sen d(null);
}
</script>

</head>

<body >
<form name="form1" >
<div align="center">
<table width="103%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabborde r">
<tr>
<td colspan="4"><di v align="left">
<input type="button" name="new_rec" value="Add New Record " >
</div></td>

</tr>
<tr>
<td colspan="4">&nb sp;</td>
</tr>
<tr>
<td colspan="4" class="box">Ban k Master </td>
</tr>
<tr>

<td colspan="4"><di v align="center">
<table width="100%" border="0" cellpadding="3" cellspacing="3" >
<tr>
<td width="17%" height="30">Bra nch Code </td>
<td width="8%" height="30"><se lect name="select _bank_branch_co des" onchange="showU ser(this.value , this.name);">
<option value="" selected >Search </option>
<option value='b101'>b1 01</option><option value='b102'>b1 02</option> </select></td>

<td width="11%" height="30">Ban k Code</td>
<td width="9%" height="30"><se lect name="select_ba nk_code" class="tabborde r" id="select5" onchange="showU ser(this.value , this.name);">
<option value="" selected >Search </option>
<option value='01'>01</option><option value='02'>02</option> </select></td>
<td width="9%">Pin Code </td>
<td width="46%"><in put type="text" name="pin" onblur="showUse r(this.value , this.name);"></td>

</tr>
<tr>
<td colspan="6"><di v id="txtHint"><b >User info will be listed here.</b></div></td>
</tr>
</table>
</div></td>
</tr>
<tr>

<td colspan="2" class="box"><in put name="save_chg" type="submit" id="save_chg" value="Save Changes"></td>
<td colspan="2" class="box"><in put type="submit" name="Submit" value="Delete"> </td>
</tr>
<tr>
<td colspan="4">&nb sp;</td>
</tr>
<tr>
<td colspan="4" class="box"><di v align="left">Li st Of All Banks </div></td>

</tr>
<tr class="tabborde r">
<td width="7%" class="tabborde r"><div align="center"> S.No</div></td>
<td width="8%" class="tabborde r"><div align="center"> Bank Code</div></td>
<td width="49%" class="tabborde r"><div align="center"> Branch Code </div></td>
<td width="36%" class="tabborde r"><div align="center"> Branch Address </div></td>

</tr>
<tr class='tabborde r'><td class='tabborde r' align='center'> 1</td><td class='tabborde r' align='left'>b1 01</td><td class='tabborde r' align='left'>01 </td><td class='tabborde r' align='left'>ja nakpuri</td></tr> <tr class='tabborde r'><td class='tabborde r' align='center'> 2</td><td class='tabborde r' align='left'>b1 02</td><td class='tabborde r' align='left'>01 </td><td class='tabborde r' align='left'>Vi kaspuri</td></tr> </table>
</div>
</form>

</body>
</html>
[/HTML]
Jun 5 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
Ah, I see. The code will obviously be added via Ajax.

OK, so now load the requested page directly in the browser with the parameters you would pass when making the Ajax request, e.g. "get_bank_branc h_code.php?q=01 &name=select_ba nk_code" and check the source and display that here.
Jun 5 '08 #8
Shalini Bhalla
190 New Member
After requesting above url with variable what ever code i got was corrected and noe i am getting this but , values still are not getting updated


[HTML]<form name='form2'><t able width='100%'><t r><input name='branch_co de[0]' type='hidden' value='b101'/>

<td>Bank Code </td><td><input type="text" name="bcode[0]" value=" 01" onblur="modify_ rec('01', 'b101', this.value,'ban k_code')" /></td>

<td>Branch Code </td><td><input type="text" name="brcode[0]" value=" b101" onblur="modify_ rec('01', 'b101', this.value,'bra nch_code')" /></td>

<td>Branch Address </td><td><input type="text" name="badd[0]" value=" janakpuri" onblur="modify_ rec('01', 'b101', this.value,'bea nch_address')" /></td>

<td>Pin</td><td><input type="text" name="pincode[0]" value=" 110018" onblur="modify_ rec('01', 'b101', this.value,'Pin code')" /></td>


<tr><input name='branch_co de[1]' type='hidden' value='b102'/>

<td>Bank Code </td><td><input type="text" name="bcode[1]" value=" 01" onblur="modify_ rec('01', 'b102', this.value,'ban k_code')" /></td>

<td>Branch Code </td><td><input type="text" name="brcode[1]" value=" b102" onblur="modify_ rec('01', 'b102', this.value,'bra nch_code')" /></td>

<td>Branch Address </td><td><input type="text" name="badd[1]" value=" Vikaspuri" onblur="modify_ rec('01', 'b102', this.value,'bea nch_address')" /></td>

<td>Pin</td><td><input type="text" name="pincode[1]" value=" 110048" onblur="modify_ rec('01', 'b102', this.value,'Pin code')" /></td></table></form>[/HTML]
Jun 6 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
If you look at the values, each of them has a space before them. That's the problem. Remove the spaces and it should hopefully work.
Jun 6 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2424
by: vanisathish | last post by:
Hi I am running a client side javascript timer to periodically refresh the contents of some tables in the HTML page. The table values are dynmically binded from XML DOM object using the <XML tag in HTML>. The data is getting updated properly. but whenever the value is refreshed, the HTML page flickers. How do i avoid this flickering.. ...
0
1072
by: Lakshmi Narayanan.R | last post by:
Hi Experts I am new to .NET. I need great explanation for "the updation in the disconnected data". How it is handled. That is, if mutiple user is interacting with the data, one will delete another will insert or update. So after the modifications how the correct updation is made in the database table. What the hidden mechanism is there. The...
1
1202
by: Babz | last post by:
Hi, How I can prevent concurrent updation of a records in .net. I am using Dataset which is disconnected from the data source. In this situation if two users opens the same record, modifies the data and updates one after another, my data won't be in the correct state. How I can prevent this. Is there any locking technics.
16
2770
by: Vibhu | last post by:
Hello All, I am trying to update a database using dataset but seems that I am missing out something. After going through a lot of posts and checking my code, I am still at my wits end to figure out how to do a simple update. Here is the code. Any help would be greatly appreciated. Regards,
1
2027
by: r2destini | last post by:
Hi Friends, I am new to .Net. So I don't know much. I am facing a problem in updating database through ADO.Net I am creating the dataset and there is no problem in the updation and deletion or insertion in the dataset but when I am updating the
0
1284
by: prashant | last post by:
Hi, I am trying to set up Transactional replication with immediate updation. The configuration is as follows: 1. Publisher is SQL server 2000 Enterprise Edition, and Distributor is on the same server. 2. Publisher SQL server is installed on Windows 2003.
1
1830
by: roshan56us | last post by:
Hi, i have problem in updation of access database, which is in backend and Visual basic as front end. its using 800 records in MS-Access but,while updating the database, it doesn't update sometime or sometime it takes two to three times in updation.and sometime application has to be closed and then reopened ,then update. and it get updated.
1
1677
by: siri11 | last post by:
Hi everyone!!!!!!!!! If i update a record in a table in sqlserver from front end (c#.net),using a stored procedure for updating then after updation if i open the table then it is showing the same record 2 times i.e before updation record and after updation record..Plzzzzzzzz help me how to solve this problem....its very urgent...Plzzzzzzzzzz ...
2
1746
by: saga git | last post by:
how to write javascript validations for database updation
0
7704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7620
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7985
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5234
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3666
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3659
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1230
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
959
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.