Tuesday 15 June 2010

javascript - user profile update via ajax -



javascript - user profile update via ajax -

hi guys im trying update user details via ajax not updating users table , stop executing when possessing... appear here code please help if possible

edit_profile.php

<?php if(isset($_post["la"])){ $firstname = strip_tags(preg_replace('#[^a-z0-9]#i', '', $_post['fi'])); $lastname = strip_tags(preg_replace('#[^a-z]#', '', $_post['la'])); $age = strip_tags(preg_replace('#[0-9]#', '', $_post['ag'])); $gender = strip_tags(preg_replace('#[^a-z]#', '', $_post['g'])); // form info error handling if($gender == "" || $firsname == "" || $lastname == "" || $age == ""){ echo "some business relationship info empty."; exit(); }else{ $sql = "update users set gender='$gender', age='$age', lastname='$lastname, firstname='$firstname' username='$log_username' limit 1"; $query = mysqli_query($db_conx, $sql); echo "account_success"; exit(); } } ?>

ajax , js

<script type="text/javascript" language="javascript"> function _(x){ homecoming document.getelementbyid(x); } function toggleelement(x){ var x = _(x); if(x.style.display == 'block'){ x.style.display = 'none'; }else{ x.style.display = 'block'; } } function restrict(elem){ var tf = _(elem); var rx = new regexp; if(elem == "firstname"){ rx = /[^a-z0-9]/gi; } else if(elem == "lastname"){ rx = /[^a-z0-9]/gi; } tf.value = tf.value.replace(rx, ""); } function emptyelement(x){ _(x).innerhtml = ""; } function ajaxobj( meth, url ) { var x = new xmlhttprequest(); x.open( meth, url, true ); x.setrequestheader("content-type", "application/x-www-form-urlencoded"); homecoming x; } function ajaxreturn(x){ if(x.readystate == 4 && x.status == 200){ homecoming true; } } function update_profile() { var fi = _("firstname").value; var la = _("lastname").value; var g = _("gender").value; var ag = _("age").value; var status2 = _("status_profile"); if(fi == "" || la == "" || ag == "" || g == ""){ status2.innerhtml = "fill out of form data"; status2.style.color = "red"; }else { _("profilebtn").style.display = "none"; status2.innerhtml = 'processing ...'; var ajax = ajaxobj("post", "edit_profile.php"); ajax.onreadystatechange = function() { if(ajaxreturn(ajax) == true) { if(ajax.responsetext != "account_success"){ _("profilebtn").style.display = "block"; } } } ajax.send("&fi="+fi+"&la="+la+"&g="+g+"&ag="+ag); } } </script>

the html

<div class="row profile-classic"> <div class="col-md-12 m-t-20"> <form name="updateform" id="updateform" onsubmit="return false;"> <div id="profile_form" class="panel"> <div class="panel-title line"> <div class="caption"><i class="fa fa-phone c-gray m-r-10"></i>account</div> </div> <div class="panel-body"> <div class="row"> <div class="control-label c-gray col-md-3">username:</div> <div class="col-md-6"> <input type="text" class="form-control" value="<?php echo $uname; ?>" disabled="disabled"> </div> </div><br /> <div class="row"> <div class="control-label c-gray col-md-3">firstname: *</div> <div class="col-md-6"> <input type="text" onfocus="emptyelement('status_profile')" class="form-control" id="firstname" contenteditable="true" value="<?php echo $firstname; ?>"> </div> </div><br /> <div class="row"> <div class="control-label c-gray col-md-3">lastname: *</div> <div class="col-md-6"> <input type="text" onfocus="emptyelement('status_profile')" class="form-control" id="lastname" placeholder="your lastname" value="<?php echo $lastname; ?>" > </div> </div><br /> <div class="row"> <div class="control-label c-gray col-md-3">age: *</div> <div class="col-md-6"> <input type="text" onfocus="emptyelement('status_profile')" class="form-control" id="age" value="<?php echo $age; ?>"> </div> </div><br /> <div class="row"> <div class="col-md-6"> <select class="form-control" onfocus="emptyelement('status_profile')" id="gender" class="form-control"> <option value="<?php echo $gender; ?>"><?php echo $sex; ?></option> <option value="m">male</option> <option value="f">female</option> </select> </div> <button id="profilebtn" onclick="update_profile()" class="btn btn-sm btn-default"><i class="fa fa-floppy-o"></i> save</button><span id="status_profile"></span> </div><br /> </div> </div></form> </div></div>

you can utilize mysqli_error($db_conx) determine error is... have javascript display nicely you.

but - variable in where clause ( $log_username ) undefined.

javascript php ajax

No comments:

Post a Comment