In previous post, I told you how to insert value into database using JavaScript and Ajax. Now i am going to tell you how to edit and update the value in Database.
In this you have to continue previous tutorial post.
there is a JavaScript code from which you have to call one PHP page from that you will get the value from database and that value will continuous fill into the field again for update.
in this code firstly you are going to ask and confirm that "Are you sure you want to edit value".
Step 1 - edit code (JavaScript).
Step 2 - PHP page that will get the value from database and echo the response again to JavaScript code.
Step 3 - After getting response from PHP file. update button will active after the submit button but submit button will be deactivate due to Update Button. in this i am using on hidden fields in which record id will store for update Record.
Step 4 - For update record click on update button. then update function will work that will get the hidden id as a record ID and update the record corresponding.
Still if you face any problem then contact me from the contact page. surely i will response you as early as possible.
In this you have to continue previous tutorial post.
there is a JavaScript code from which you have to call one PHP page from that you will get the value from database and that value will continuous fill into the field again for update.
in this code firstly you are going to ask and confirm that "Are you sure you want to edit value".
Step 1 - edit code (JavaScript).
function edit_cir() { var confirmation=window.confirm("Are you sure you want to Edit?") if (confirmation) return true; //window.alert("Good!"); else return false; //window.alert("Too bad") } function edit_circle(id) { if(edit_cir()) { var edit_circle = id; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var res = xmlhttp.responseText; alert(res); if(res!="0") { var response = res.split("@"); document.getElementById('update_circleid').value = response[0]; document.getElementById('circle_name').value = response[1]; document.getElementById('account_name').value = response[2]; document.getElementById('submit_circle').style.display="none"; document.getElementById('update_cirlce').style.display="block"; } } } var string = "ajax_page/update_data.php?edit_circle=" + edit_circle; xmlhttp.open("GET", string, false); xmlhttp.send(); } }
Step 2 - PHP page that will get the value from database and echo the response again to JavaScript code.
// var string = "ajax_page/update_data.php?edit_circle=" + edit_circle; if(isset($_REQUEST['edit_circle'])) { $id = $_REQUEST['edit_circle']; $fetch = mysql_query("select * from ms_circle WHERE id = '$id'"); while($row = mysql_fetch_array($fetch)) { $id = $row['id']; $circlename = $row['circlename']; $account_type = $row['account_type']; echo $id."@".$circlename."@".$account_type; } }
Step 3 - After getting response from PHP file. update button will active after the submit button but submit button will be deactivate due to Update Button. in this i am using on hidden fields in which record id will store for update Record.
Step 4 - For update record click on update button. then update function will work that will get the hidden id as a record ID and update the record corresponding.
function update_acc() { var circleid = document.getElementById('update_circleid').value; var account_name1 = document.getElementById('account_name').value; var circle_name = document.getElementById('circle_name').value; //var table_field = document.getElementById("db_table"); if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var res = xmlhttp.responseText; if(res=="c" || res=="C") { alert("Circle Updated"); window.location.reload(); } } } var string = "ajax_page/update_data.php?circleid="+circleid+"&account_nam="+ account_name1 +"&circlename=" + circle_name; xmlhttp.open("GET", string, false); xmlhttp.send(); }
if(isset($_REQUEST['circleid'])) { $circle_id = $_REQUEST['circleid']; $account_type = $_REQUEST['account_nam']; $circlename = $_REQUEST['circlename']; $updated = mysql_query("UPDATE ms_circle SET circlename = '$circlename', account_type = '$account_type' WHERE id = '$circle_id'"); if ($updated) { echo "c"; } }
Still if you face any problem then contact me from the contact page. surely i will response you as early as possible.
0 comments :
Post a Comment