Support » Fixing WordPress » Delete rows from custom table in db

  • I have a table i created in the database that holds simple information on projects like their title, description etc…

    I want to add a link that will allow users to delete all date on that certain project if they wish.

    Below is the code I have so far but when I click the button it does nothing.

    if (isset($_POST['delete_all'])) {
    	global $wpdb;
    			'DELETE * FROM $wpdb->mg_project_info
    		 	WHERE project_title = "'.$album.'"
                AND user_name = "'.$user_name.'"'
    		  'DELETE * FROM $wpdb->mg_project_images
    		   WHERE project_title = "'.$album.'"
               AND user_name = "'.$user_name.'"'


    <form action="mylink" method="post" enctype="multipart/form-data">
    <input type="submit"  name="delete_all" value="Delete Project"  />

    any help would be appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I have since removed the * after the DELETE as I was informed thats not allowed but still no joy. it just doesn’t do anything (to the table/rows).

    Hi mikegarlick,

    The sql looks ok, but sometimes it’s difficult to see what’s actually happening.
    For debug purposes, look for and install a plugin called Blackbox – that will tell you what SQL was actually run, and if it created any errors.

    Other suggestion would be to use a ‘projectid’ field, rather than trying to match on user + title.
    My 2 cents 🙂

    thanks for your input jibbius 🙂

    It means re-jigging my tables and initial INSERT sql but yeah thats probably the best way forward using the ID.

    No worries.

    In theory, your method should still have worked.
    Try the blackbox plugin, and see what sql it ran (if any). It slows the site a little, so deactivate it when you’re done.

    If it’s not running any sql – then your problem is in the form/submit.
    If it IS running the SQL, but nothing got deleted:
    – copy and paste it into phpmyadmin
    – replace the delete with ” select * “
    – play around with it till you start seeing some rows.


Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Delete rows from custom table in db’ is closed to new replies.