Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to update database onclick?

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #242560
    cscodismith
    Participant

    I currently am in the process of setting up an ‘admin panel’ where those users who have admin_level 2 have a module that are displayed to them on the homepage that look something like this. I want it so upon the level 2 Administrator clicking on 1 / 2 it will change the admin level of the user in that table with it. I am not sure how exactly to do this with an onclick function and not sure what more to put in my query?

    $connStr = 'mysql:host=localhost;dbname=heartfx_website';
    $user = 'root';
    $pass = '';
    $conn = new PDO($connStr, $user, $pass);
    
    // update
    $update = $conn->prepare("UPDATE admin_level FROM users SET ? WHERE ")
    

    Any help would be greatly appreciated!
    Best regards,
    Codi

    #242571
    rkieru
    Participant

    This strikes me as more of a Javascript problem than one directly-related to PHP. If my understanding is correct, you are providing a button that will allow an authorized user to change the access level of a user when clicked.

    So there are two ways to achieve this.

    Apply and Redirect

    In a scenario like this the button would either be a link or a form that takes the user off the current page, applies the update, and then returns the user to the original page.

    So for example: <a href="level.update.php?user=25&level=2">...</a>

    The user would then be directed to that page (assume it has the code you presented above) and then redirected upon completion back to the list of users via header("Location: path/to/list");

    Apply Asynchronously

    In a scenario like this, the button would function much the same, except you would be submitting the call via AJAX and notifying the user of the results. In this situation the user would never leave the current page.

    For this to work you would have a button or link of some sort keyed to a Javascript AJAX call. How you handle parsing the various information is up to you, whatever Javascript libraries you are using (if any), etc. With jQuery this would be via $.ajax().

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.