jquery - Update MySQL using AJAX and PHP -
i'll go slow, not sake..for mine. i'm real new @ trying to this. i'm trying update live mysql db html table. how each built.
 echo ("<td id=\"callsign:$row[recordid]\" contenteditable=\"true\"                  onclick=\"showedit(this)\"                 onblur=\"savetodatabase(this,'callsign',$row[recordid])\"                  style='text-transform:uppercase'>                 $row[callsign]</td>");   this how renders.
 <td id="callsign:6" contenteditable="true" onclick="showedit(this)" onblur="savetodatabase(this,'callsign',6)" style="text-transform: uppercase; background-color: rgb(253, 253, 253); background-position: initial initial; background-repeat: initial initial;">                 ka0sxy</td>   here function gets called.
 function savetodatabase(editableobj,column,id) {          $(editableobj).css("background","#fff url(loadericon.gif) no-repeat right");             $.ajax({                 url: "saveedit.php",                 type: "post",                 data:'column='+column+'&editval='+editableobj.innerhtml+'&id='+id,                 success: function(data){                     $(editableobj).css("background","#fdfdfd");                 }               });       }   and here php.
 <?php require_once "dbconnectdtls.php";      $result = mysql_query("update netlog set " . $_post["column"] . " = '".$_post["editval"]."'  recordid=".$_post["id"]);     echo $result;   ?>   when tab cell next thing gets executed .gif. mysql not updated, doing wrong?
thanks in advance not treating me dummy, helping me learn.
followup suggestions:
i'm afraid i'm making no headway on this. willing write working example can follow?
for newcomer there many things should take care in script:
- first have avoid insertion of $_post values directly query may lead sql injection problems.
 - you should use pdo or mysqli perform query same paranoidal reasons.
 - you should consistent. why use .innerhtml when using jquery? use $(editableobj).html()
 - you don't show javascript errors: viewing console? try right clicking in body of page , selecting "inspect element" click on "console" tab of frame appears.
 also not printing "data" variable gets returned see if expected result in server. with:
console.log(data);
other looks in script ;)
Comments
Post a Comment