Improved Ajax Add, Edit & Delete From MySQL Tables

Posted 2 months, 3 weeks ago at 6:11 pm. 120 comments

Update: Version 2.1 of this script is now available. I highly recommend that you download the new version. You can get it here.
Someone asked me in a comment how you would add another entry field to the previous version of this code & well I couldn’t really answer the question. It proved to me what I already knew, the code needed re-writing.

So I have sat over the past few days, in between building my sisters computer, re-writing it. I has been hard but I think it finally does what I had envisioned in the first place. The last codes ease of use was also rubbish so I have tried to improve that a lot too. If you want to try out the result before downloading you can here.

The files themselves are commented with the instructions on how to make it work for you. I will repeat the instructions here though. I was going to detail how it works but I tried and failed. Every time it gets too complicated too quickly. If you want to know the technical details then ask in a comment and I’ll try and show you.

You can download the file here:

Download: Improved Add Edit Remove From MySQL Using AJAX  Improved Add Edit Remove From MySQL Using AJAX (21.6 KB, 0 hits)

Here are the instructions. First you need to find every reference to ajaxDelete and change it to the name of your database table. Oh and you need to change the connection info. Both are marked in the file. Next you will need to change the reference to the tables primary ID. They are marked in the file so they should be easy to find.

There are also instructions on how to add extra fields into the code. Finally I have included the modified version of jEditable in the rar file. It is only two lines but they stop strange things happening with the table colors.

Ok hopefully that will work a lot better. I am working on a version made into a PHP class that will be useable just by writing a few lines but that is still quite a while off yet. Also I haven’t included any code that stops or disables the enter button so if you press it, the page will refresh. I will still add the info though. I have to work on that but that is another tutorial.

Thanks for reading again and sticking with my blog. If you have any questions about the code or anything else please leave a comment. ;)

UPDATE: I have added a sorting function as per Nick’s request. It can be seen in the demo and you can download the updated version below. I am leaving the other version available for download for the moment just in case you do not want the table sorting ability. Thanks to Christian Bach for the Tablesorter plugin that makes it work. Also please note the tablesorter plugin has been altered slightly so you need the version inside the download.

Download: AEDS Via Ajax  AEDS Via Ajax (23.3 KB, 0 hits)

I am going to improve it a little more by making it into a fully functional class which should be much, much easier to use. For that part I need your help. I am looking for a name for this little application here is a run down of it’s features:

  • Add information on-the-fly
  • Edit information on-the-fly
  • Remove information on-the-fly
  • Sort information on the fly
  • Exclude columns
  • Automatic column recognition. Just add it to the table and the PHP will figure out the rest

There are some other features but those are the major ones. If you can think of a name please leave you idea in a comment or if you can think of a feature that it desperately needs I will try and add it when I make it into a class. Again thanks for sticking with my blog & I hope you like this update. ;)

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • StumbleUpon
  • Google
  • Furl
  • del.icio.us
  • Facebook

120 Replies

  1. Thanks, this is what I need. A question, how hard would it be to restrict edits to only some authorized users? A pointer in the right direction would be most appreciated :)

  2. Hi Nick,

    If you already have a user & registration system built then it would probably quite easy. For example you could use SMF’s SSI include to restrict access to only people who are registered on your SMF forum.

    If however you need to build a user system that would be a whole other tutorial. If you let me know whether you have a user system built already or not I can try and help you from there.

    Glad you liked the code. :)

  3. Val Vankov Gravatar Apr 10th 2008

    Just what i need :) i’ve been searching for something like this for a week. :) Thank You! :)

  4. Hi Val,

    No problem. If you or anyone else has any suggestions for improvements I will try and add them. :D

  5. Ok, try this one on for size :) How about the ability to sort on other fields besides the id? Say sort the name alphabetically, or something like that?

  6. By the way, I don’t have an existing user system… :(

  7. @nick: Well as for the sorting. Sorting by any other means is quite easy you can just change the query on the listmulti.php page to list anything in a-z order or z-a for that matter. The problem comes when adding a new row via AJAX. It will automatically put it after the last row, so there would have to be a way for it to figure out where to put the new row. That could be quite challenging but I’ll have a look into it. Thanks for the suggestion.

    @nick again: In that case you would need to build a small user authentication system. You could use another DB table with authentication information in it such as a username & password. All you do is make a small form that you reach before the main listmulti.php page. Have the form submit to a script that takes the username & password. Checks the username & then hashes the password using md5 or shal and checks it against the password which is already stored as the respective hashed string. Of course you would also have to make a registration system or you could personally make each user inside phpmyadmin or whatever MySQL admin you use.

    I hope that answers at least some of your question from before. If you want I can make a tutorial on a small user registration & authentication system. Just let me know and I’ll see what I can do. ;)

  8. Thanks for the reply! If the simple user registration tutorial is something that you think others might benefit from, then by all means :)

    The sorting is more important right now, and my question is a bit more in depth about that. What I think would be cool is to let the user pick which columns to sort by. I know I could change the query to initially sort by something else, but letting the user do it seems much more complex (at least to my feeble mind)

    Anyway, thanks again for the code :)

  9. @nick: Yeah, I think user registration is something that comes up a lot so I’ll do a small tutorial on that later.

    As for the sorting, I meant to add that you could have a set of buttons above the table to change the query at the users discretion however you still have the problem of how to get the added row to know which row to appear under when the new row is returned via AJAX. I don’t think it’s impossible but I can see it being hard.

    Don’t worry your mind is fine, I find what you have asked complex too and I wrote the code, lol. I shall see what I can do though, so drop back soon. :D

  10. thanks for the nice tutorials, will check back often for new ones.

  11. @Ryan: No problem, I’m glad you like them. I have just finished integrating Nick’s request from above about the sorting. I’m going to put it up shortly.

  12. Sweet, thanks so much! You have made me a faithful reader.

  13. Thanks, but I don’t see the updated ajaxmulti.php and listmulti.php files in the new archive file…

  14. @Nick: Sorry about that was Winrar being a pain. I never noticed that it decided to delete the two files instead of updating them. It’s probably my fault but I’m just gonna blame Winrar instead. ;)

    The files should be in there now. :)

    Thanks for reading and I’m glad you like my posts. Remember if you have anything you’d like help with just ask, I’m always looking for ideas for new tutorials.

  15. Thanks.
    This is the one that I’m looking for.
    Problem how do I convert this using odbc instead of mysql class. I convert some to odbc the delete is working fine, but the update won’t update and when I submit I can’t get the value. Any hints?

  16. Disregard about the value Duh..I got the value
    I put the wrong variable..:)

  17. forgot but still won’t update and won’t insert data..ehm

  18. Hi ant,

    I’m sorry but I can’t help you there as I haven’t got any experience at all with odbc.

    As for the won’t update or insert problem, it may be related to the change from MySQL to odbc but I doubt it. Have you added the line into the javascript for your table fields? That would be the line that goes:

    58
    
    name = $('input#name').val();

    you need to change it for each input field you add, and you also need to add it onto the line below that.

    It should be written on the file in comments but I forgot to add them, I’ll update the rar now with a version with comments.

  19. is this name = $(’input#name’).val(); need to be in listmulti.php? I already have this.

    I’ll let you know if I can get it to work in odbc

  20. Yes the name = $(’input#name’).val(); is already in the page but you need to change it to match your input fields.

    If for example you have a input named age with the id age you would change it to age = $('input#age') you would also need to add it to the url below that line.

    Sorry it couldn’t be simpler but that was the best and easiest way I could work out. I’m always trying to update my code though so maybe I can make it easier at some point.

    Yes please let me know if you can make it work for odbc and I’ll put a version up for download.

    Thanks. Sorry I couldn’t be of more help. :(

  21. Well done!!

    One thing I’ve noticed is that it seems to strip any special characters. Where is this done?

  22. Hi Dave,

    You noticed right, it is done in the function mysqlCleanUp located at the very top of ajaxmulti.php and is mostly to protect the database from characters that can be used in a dangerous way. Generally addslashes() will do enough but you might want to change this bit of code:

    4
    5
    6
    7
    8
    
    function mysqlCleanUp($v) { 
    	$v = preg_replace("/[^a-z0-9 ']/is", "", $v);
    	$v = addslashes($v);
    	return $v;
    }

    to something like this:

    4
    5
    6
    7
    8
    9
    10
    
    function mysqlCleanUp($v) { 
    	if (get_magic_quotes_gpc()) :
               $v = stripslashes($v);
            endif;
            $v = mysql_real_escape_string($v);
    	return $v;
    }

    That should stop it stripping special characters and keep your database secure.

    Hope that helps and glad you liked the code. :)

  23. Thanks for that! Right after I wrote it I found where it was doing it! :)
    Again - great tutorial. I’m sure we’ll make great use of it.

  24. One more question - sorry!

    My hopes are to use something similar to what you have built here for the obvious back and forth between a MySQL DB and the broswer. What if I have a table that has 6 or 7 fields but I only want to be able to edit/add on 4 or 5 of these fields.

    When I make the modications to your app and save, I have some mystery 0’s or ‘click to edit’ fields. When I do (in testing) it writes the data to the fields I haven’t referenced in the DB. Any thoughts?

    Many thanks!

  25. Nevermind. I saw where to make the change!

  26. Hi Dave,

    I hope you sorted all that out. Just in case you didn’t there should be a exclude array that you can use. I think I forgot to mark it in the code, sorry.

    Glad you like the code & sorry for not replying sooner I’ve been scanning in some pictures from some old FHM’s. I have around 100 of them from my teenage years, and they are starting to crack the wall beneath the landing. :o

    Saying all that I might do a magazine scanning tutorial. :D

    Thanks again Dave and I’m glad you got everything sorted. Anymore problems just give me a shout. :)

  27. I got the delete and update to work with odbc but still having problem with insert. The insert is working but I need to reload the page to see the value. Can you tell me which part that I need to fix to see the value without reloading the page?

    Anyway below is the odbc code for delete:

        case "delete" :
            $query = ("DELETE FROM ajaxDelete WHERE id = '".$id."'") or $failed = true; //change ajaxDelete and id to your primary ID
            odbc_exec($conn, $query); 
            if($failed == true) :
                echo "Sorry, the removal of that row was not possible. Please try again later.";
            else :
                echo "Removal successful.";
            endif;
       break;

    for update:

    default :
            $v = $_POST['value'];
            $v = mysqlCleanUp($v);
            $ex = seperateID($_POST['id']);
            $ex['field'] = mysqlCleanUp($ex['field']); 
            $query = ("UPDATE ajaxDelete SET $ex['field'] ='".$v."' WHERE id = '".$ex['id']."'"); //change ajaxDelete and id to your primary ID
            odbc_exec($conn, $query) or $failed = true; 
            if($failed == true) :
                echo "Sorry, the update of that row failed. Please try again later."; 
            else :
                echo stripslashes($v)."|Excellent, your edit was updated successfully."; 
            endif;
        break;

    Admin: Did a little cleaning of your post Ant by putting the code in code boxes. Look further down for your reply, for some reason Wordpress decided this comment needed moderating and I hadn’t noticed, Sorry.

  28. Great work but i have a question.

    for example i have download from http://freerichtexteditor.com/page/4.htm

    how i can use this ? i was try like that

    content = $(’input#content’).val();
    but it isnt working what i can write instead of ‘input’ ?

    thanks,

  29. Hi Burclar,

    Since the rich text editor you have linked to isn’t a input field that code wouldn’t work, as you know, lol.

    I’m not sure what to write as the rich text editor creates an iFrame and loads content in to it. However from looking at it my best guess would be something like this:

    1
    
    content = $(’iframe#freeRTE body’).val();

    Where freeRTE would be the name of the iFrame used for the editor. It is only a guess but hopefully it will work for you. If not let me know and I’ll have another look.

    Thanks for looking.

  30. @Ant: It sounds like the Javascript isn’t adding the new table row to the bottom of the table.

    This problem generally occurs due to javascript not splitting the info it gets from the PHP script. All I can suggest is to make sure the createTable function on the ajaxmulti.php page has an asterisk(*) in the variable $html.

    That’s my best guess I’m afraid. If you can give me anymore info on any errors or anything like that it would be a great help.

    Sorry I can’t help more but if this doesn’t work feel free to ask me again.

    Thanks.

  31. I got it..:)
    I got the last id wrong since i didn’t know to convert msql_insert_id, but actually you can use SELECT SCOPE_IDENTITY() as my last id and now is working …yeah..thank you so much

  32. Hey Ant.

    Glad you got it working. I didn’t know about SCOPE_IDENTITY() so thanks for teaching me that. ;)
    Well Done. :)

  33. hey Veneficus Unus,
    i tried your code but not working…

    content = $(’iframe#freeRTE body’).val();

  34. Hi again Burclar,

    I will have a look tomorrow for you as I am very busy right at this moment in time and to help you I’ll have to download the rich text editor and give it a go myself.

    I do however have one more suggestion for what you. Try this code instead:

    content = $(’iframe#freeRTE body’).html();
  35. not working Veneficus Unus,
    i will wait for solutions….

  36. hi.

    i really like this piece of plugin, code you have. but everytime i try downloading the file, it is totally blank in winzip.

    no files in it.
    can you help plz.

    thanks

  37. @Smith: I haven’t used winzip in a loooong time but I have tried the code downloads in winrar & a free zip program called peazip and they work great. I have also tried downloading on another computer I have running Ubuntu Linux and that works fine too.

    I really don’t know what is going on, sorry. All I can suggest is to try another zip program. If you need a free one try peazip or you can try the 30-day evaluation of winrar.

    Thanks for the comment & sorry I can’t help more.

    @Burclar: I am still looking into the problem with the rich text editor for you. ;)

  38. @Burclar: Try this code Burclar:

    1
    
    content = freeRTE.document.body.innerHTML;

    If you’re wondering about the code change, I can’t find a way for jQuery to retrieve the content of an iFrame. So we use a little bit of classic DOM traversing instead.

    I have tried it and it gets the content of the rich text editor exactly like it should.

    Let me know if you get it working or if you have any more problems.

  39. Veneficus its amazing thanks man …when i try to post some text like

    Try me man

    its posting into db like that

    “bfontsize6Trymemanfontbbr” So its craping html codes do you know any solutions for that ?

    and can i post text cyrilic ? i know i have alot of questions i am very very sorry man…

  40. i change little mysqlCleanUp function but still not working ..

    $asc2uni = Array();
    for($i=128;$i<256;$i++){
    $asc2uni[chr($i)] = “&#x”.dechex($i).”;”;
    }
    function mysqlCleanUp($v) {

    global $asc2uni;
    $v = str_replace(”&”, “&”, $v);
    $v = str_replace(”", “>”, $v);
    $v = str_replace(”‘”, “'”, $v);
    $v = str_replace(”\”", “"”, $v);
    $v = str_replace(”\r”, “”, $v);
    $v = strtr($v,$asc2uni);
    $v = htmlentities($v);
    $v = addslashes($v);

    return $v;
    }

    i am getting this error

    “INSERT INTO news ( title, created, content) VALUES ( ‘trytitle’, ‘2008-04-2023:24′, ‘<i><font size=\\"6\\"><b>try</b></font></i>’)Sorry, your entry could not be added. There may be a problem with the database. Please try again later.”

  41. @Burclar: First of all I’m glad that worked for you.

    Second to get rid of the HTML tags from the content you will need to run it through the php function strip_tags() during the mysqlCleanUp() function, sometime before addslashes().

    Third I’m not sure about cyrillic text but I don’t see any reason for it not to work.

    Forth I’m not exactly sure what you are trying to do with this code?

    $asc2uni = Array();
    for($i=128;$i<256;$i++){
       $asc2uni[chr($i)] =&#x”.dechex($i).”;”;
    }

    If the str_replace() functions are your way of trying to remove the HTML, then nice try but the strip_tags() function will do it all for you.

    Fifth I’m not sure why the database is ‘erroring’. If it errors again you should be able to see what caused it by looking at the live source code. Do that by right-clicking in your browser, and looking in the source code for the bit commented out with HTML comment tags.

    Don’t worry about all the questions that what I’m here for. I’m just glad someone is getting some use out of my code & learning something all at the same time.

    Hope that helps again. ;)

  42. LUCIO Y JOACO Gravatar Apr 21st 2008

    GROSO !!! SOS DIFERENTE EVIDENTEMENTE !!! GRACIAS…TOTALES

  43. i dont want to remove html tags when posting in db :)
    how can i modify preg_replace for that ?

  44. @Burclar: Sorry I misunderstood. To keep the HTML tags you will need to remove the preg_replace(). Change the mysqlCleanUp() function to this:

    function mysqlCleanUp($v) { 
    	if (get_magic_quotes_gpc()) :
               $v = stripslashes($v);
            endif;
            $v = mysql_real_escape_string($v);
    	return $v;
    }

    This should keep it safe when entering into the database and keep the html tags. Please remember when you retrieve the results you might need to use stripslashes() to remove the escaping from the html.

    Hope that helps.

  45. doesnt worked i am trying to post to the db

    <b>TRY</b>

    but still im getting errors

    INSERT INTO news ( title, created, content) VALUES ( 'try', '2008-04-2100:48', 'TRY');
    Sorry, your entry could NOT be added. There may be a problem with the database. Please try again later.
  46. @Burclar: It seems that there is some sort of error in the query even though I can’t see one but there must be one or it wouldn’t error.

    Could you post your table structure please so I can see if your query matches up with it.

    Also make sure you have replaced the mysqlCleanUp() function properly as your query should read:

    INSERT INTO news(title, created, content) VALUES ('try', '2008-04-2100:48', '<b>TRY</b>');
  47. this is my table structure

    CREATE TABLE IF NOT EXISTS `news` (
      `id` INT(6) NOT NULL AUTO_INCREMENT,
      `title` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL,
      `created` DATETIME NOT NULL,
      `content` TEXT COLLATE utf8_unicode_ci,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=24 ;
  48. @Burclar: Well from what I can see your query is ok. I have tested a query similar on my test database and it worked.

    On or around line 71 of ajaxmulti.php you should find this line:

    $db->query($query) or $failed = true;

    Change it to this:

    $db->query($query) or $db->raise_error();
    exit(0);

    Then when you get the error from the query use your browser to view the page source and there should be a detailed error message from the MySQL server that is in between html comments.

    That should help me narrow down what is wrong as I really can’t see anything wrong with your query.

  49. hi again Veneficus Unus,

    i have understood where is the problem …

    i have tested all of this things in my localhost :) i have uploaded to web really great working…i just wanna say thank you man.you have do god job.

  50. @Burclar: Glad you got it working Burclar and thank you for downloading it. :)

  51. hi again Veneficus Unus,

    when i try to post links like that “try.php?action=add&id=1 ”

    its not posted successful.i think the problem sourced from “&” i tried to change with
    $key = str_replace(”&”,”&”,$key);

    but its still sucks…can you help me

  52. & a m p ; this making the problem…

  53. What version of PHP is this newer version of this package written in?

  54. Burclar: I’m not exactly sure what you are referring to. If you are referring to the URL passed to the PHP from the javascript then the &(ampersand) has to be in the URL.

    If you mean you are trying to visit the URL in your browser then it won’t work. It has to be accessed by the javascript.

    Sorry if I’ve completely missed the mark but I’m not exactly sure what you mean.

    Joe: I wrote it in PHP5 on a localhost and the test on this site runs on PHP5. As far as I am aware there are not PHP5 specific functions in the code although I could be wrong as I didn’t write a lot of PHP4 code.

    Sorry to both of you for the delay in the reply. Been busy moving my other blog Celeb ‘O Rama to wordpress.

  55. Hi there!

    One thing I’ve noticed: When you update a field in FireFox the message appears above the table that it was completed. In IE it shows up in the cell you changed.

    I’m also using this solution in an iFrame and the results seem to cache in Internet Explorer. I have to right click and reload the frame for it to update properly. Has anyone else run across this or know of a solution?

    I’m not sure if one is related to the other…

    Many thanks,

    Dave

  56. Hi Dave,

    I had tested the code in IE but not noticed that problem. Is it IE6 or IE7. I can’t test IE6 as I have Vista which comes with IE7 pre-installed. Sorry. :(

    I’m not sure about the iFrame thing as I really don’t like frames. It could just be Internet Explorer being crap of course. lol.

    Seriously though, I think the status message problem may be related to IE6 being crap as I have just tested my example code in IE7 and it works ok. The message is put into the div by jQuery so if IE6 has a problem with jQuery I can’t really think of anything to fix it. I’ll keep trying though.

    Thanks for the comment. :)

  57. Hmmm I haven’t changed any of the Javascript on the page except for the call names. Can you think of something that I may have changed that may cause this? The Div works fine in Firefox…

    Oh - this is IE7 that I’m playing in as well.

    Cheers,

    Dave

  58. Just a side note: When I delete an item the Div show/hide DOES work if that narrows things down a bit…

  59. Hi, Dave

    Sorry about the late reply. Been reloading my computer after Vista crashed & trying to play GTA VI at the same time, lol. ;)

    Anyway the only thing I can think of is that there is a mismatch in div names and to check, double check & triple check that all of your div names do match.

    Although I’m not sure that the above is what is causing the problem since it works in Firefox and a id mismatch would stop it working in most, if not all browsers.

    The best advice I can give is to download the code afresh and on a new page slowly make the changes you did to the broken code until it breaks, if it does break and your not sure what the problem is give me a shout and I’ll see if I can help. :)

    Sorry about the trouble.

    P.S Just a thought but check your ajaxAdd() function looks like this one:

    function ajaxAdd() {
        $('img#loading').show();
    	name = $('input#name').val();
    	occupation = $('input#occupation').val();
    	$.ajax({
    		type: "POST",
    		url: "ajaxmulti.php",
    		data: "action=add&name=" + name +"&occupation=" + occupation,
    		success: function(msg) {
    			if(msg.indexOf("|") != -1) {
    				splitMsg = msg.split("*");	
    				$('table#Stargate').append(splitMsg[0]);
    				$('div#statusMsg').html(splitMsg[1]);
    				$('input#entry').val('');
    				$('img#loading').hide();
                                    $('input[type=text]').val('');
                                    t = setTimeout("clearStatusMsg()", 5000);
    				init();
                                    $("#Stargate").trigger("update"); 
    				$("#Stargate").trigger("reSort");
    			} else {
    				$('div#statusMsg').html(msg);
    				$('img#loading').hide();
                                    t = setTimeout("clearStatusMsg()", 5000);
    			}
    		}
    	});
    }

    minus the changed ID’s off course.

  60. GTA VI?? And here I am just getting through IV :)

    I’ll double check everything over again. I actually downloaded the package again and it still does it. Perhaps it is something on my end… If not, I’m willing to live with it! :D

    Cheers!

  61. Just noticed that mistype… :D But you knew what I meant. :)
    Mmmm. I’m a bit stumped have you tried my demo version in IE7? I tested it and it worked fine but I was just wondering if you IE7 was different, not sure how but I’ve seen stranger things happen.

    Failing that I haven’t a clue, sorry. :(

  62. Hi Veneficus!! Great tutorial!

    I have a question though.. I got everything working, however, when I refresh the page or re-visit it or edit it, I get a ‘Click to edit’ line of text that appears in all fields.
    The DB gets updated accordingly, and stores the updated infomation. Am I missing something?

    I saw that in your reply to Dave you advised him to use an ‘exclude array’. I am not quite clear what you meant though. Could you ellaborate?

  63. Heh, ok. Never mind. Figured it out.. syntax error! :)

  64. It seems I’ve ran into a problem once more.. I tried to add the ‘Age’ column next to the ‘Occupation’ one.. The Add and Delete actions work fine, however, when I try to edit a field in the ‘Age’ column, I get: “Sorry, the update of that row failed. Please try again later.”

    I have a feeling that I need to re-structure the UPDATE SQL statement, but I’m rather new to SQL.. Any suggestions?

  65. Wow, this is getting pathetic on my part.. another syntax error. :)

  66. Hi Kav,

    Sorry about the late reply, been having a few baffling coding problems with a Wordpress plugin I’m working on.

    I am going to go back to this code at another time to make it a bit more user friendly as I feel it isn’t very easy for someone with no or limited coding knowledge to use it very well.

    As for your problem can you give me the MySQL error info. To do this change this line on ajaxmulti.php:

    86
    
    $db->query("UPDATE ajaxDelete SET ".$ex['field']."='".$v."' WHERE id = '".$ex['id']."'") or $failed = true;

    with this code:

    86
    
    $db->query("UPDATE ajaxDelete SET ".$ex['field']."='".$v."' WHERE id = '".$ex['id']."'") or $db->raise_error();

    If you view the source code of the page when the editing error occurs it should show you the error in a HTML comment. That will help me a lot.

    I think it is the UPDATE query but I’m not sure why as it is generated by the PHP code automatically.

    If you can post that though I will give you as much help as possible. :)

  67. Veneficus, thanks! :) But, as I mentioned above I misspelled something and that’s why it wasn’t going. Right now it works fine with the initial UPDATE query.

  68. I was wondering, how would one go about ordering the output in a particular way. For example, automatically displaying or ordering the info by ‘Age’, and then alphabetically by ‘Name’..

    Would it be something like this:
    SELECT * FROM dbTable ORDER BY age, name
    and would this likne go in the listmulti.php file?

  69. @Kav: Oh, sorry. I’m just going insane I wouldn’t worry about it. :)
    @Kav, Again: Well that depends. If you downloaded the first code then yes that should work, yes it would be the following line on listmulti.php:

    $r = $db->query("SELECT * FROM ajaxDelete ORDER BY id") or $db->raise_error();

    You would change the query in there.

    The problem with that is that when you add a item it will automatically add it to the bottom of the table which is why I made the second code with the javascript auto-sorter. If that isn’t a problem the great. :)
    However if you downloaded the second code with the javascript sortable columns, that’s the one a little further down this post, then you need to change a little bit of js code.

    If you do have the code with the sortable tables it should have a bit of code that looks like this:

    $(document).ready(function() {
    	init(); 
    	$("#Stargate").tablesorter({
    		widgets: ['zebra'],
    		sortList: [[1,0]]
    	});
    });

    You just need to change the sortList: [[1,0]] to something like sortList: [[3,0], [1,0]]. I think.

    I hope that helps you. :)

  70. Yeah, that did it! Thanks again! :)

  71. No problem Kav, glad you got it all working.

  72. Hi again Veneficus, I was wondering.. is it possible to change the values of both Name and Occupation columns upon a single edit?

    For example, editing a field in the Name column would edit the corresponding Occupation field with the same information. So, I guess it’s more appropriate to say that editing a field in the Name column would replace the corresponding field in the Occupation column??

  73. nm, got it :)

  74. Hey Kav,

    Would you mind posting the code you changed to do this please. I am trying to update the code & make it a little better and it would be nice to see how you did that.

    Glad you got it sorted though. ;)

  75. Heh, actually I thought I got it but it turns out I was wrong. I tried to edit some things but they just screwed up the general functionality so I gave up on it and reverted back to the original code.

    What I am trying to figure out now is how to block the editing option for the Occupation column altogether. If you could throw some ideas my way that’d be great. Anyway, for now I’ll go take my chances and hopefully I’ll have more success than I did with the double edit thing. :)

  76. btw, when I was trying to do the double edit thing.. I put a second UPDATE command after the first one.

    When I was testing it it was something like:

    $db->query(”UPDATE table SET occupation WHERE id = ‘1′”) or $failed = true;

    This actually edited the field that you’d click on, succcessfully, but it didn’t do anything to the Occupation field. Additoanlly, the failure message of ‘Sorry, the edit…’ appeard in name field.. even though the name field was editted without a problem.

    But, yeah as I mentioned, I decided to try to block edits to the occupation field instead. Which appears to be a just as confusing so far

  77. Hey again Kav,

    So if I understand you correctly you want to disable the editing on the Occupation field? well I have had a look and I think if you change this on listmulti.php:

    <td id="occupation|<?php echo $row['id']; ?>" class="edit" align="center"><?php echo $row['occupation']; ?></td>

    to something like this:

    <td align="center"><?php echo $row['occupation']; ?></td>

    It should disable editing for that field.

    I hope that works as I haven’t been able to test it out since I haven’t got my localhost running again. Damn Vista crashing on me. :(

  78. Yeah, that works! Thanks :)
    But, what about if you want to disable the onclick sort for one of the table headers?

    I was fiddling with some things and disabled the header onclick sort, but that also disabled the editable functionality.. I’ll keep trying though, but if you have any suggestions I’ll gladly take’em :)

  79. Hey again Kav,

    If you find the code that looks something like this:

    $(document).ready(function() {
    	init(); 
    	$("#Stargate").tablesorter({
    		widgets: ['zebra'],
    		sortList: [[1,0]]
    	}