Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 2 of 2

Thread: AJAX update

  1. #1
    Join Date
    Aug 2008
    Posts
    36
    Tokens
    0

    Default AJAX update

    Im using Scriptaculous' Ajax.InPlaceEditor and i have this :

    Code:
    <span id="status"> <?php echo $usrd[status]; ?> </span>
    <script type="text/javascript">
    <!--
    new Ajax.InPlaceEditor('status', 'ajax.php');
    -->
    </script>
    But i dont no how to update the database in the ajax.php file i tried:

    PHP Code:
    <?php
    include("include/core.class.php");
    //SQL QUERY
    $dsql="UPDATE user SET status='".$usrd[status]."' WHERE id ='".$usrd[id]."'";
    $dupdate=mysql_query($dsql) or die ("Couldn't Execute Command");  
    ?>
    But it didnt update nothing, any ideas?


    EDIT: nvm worked it out, apparently it automatically sends a post with the variable $value so i just done this

    PHP Code:
    <?php
    $value 
    $_POST['value'];
    $dsql="UPDATE user SET status='".$value."' WHERE id ='".$usrd[id]."'";
    $dupdate=mysql_query($dsql) or die ("Couldn't Execute Command");  
    echo 
    $value;
    ?>
    Last edited by Coda; 28-08-2008 at 01:11 PM.

  2. #2
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    good to see you fixed it, just put it through some basic filters to stop SQL injections. Dont want internet nasty's messing around with your site

    PHP Code:

    // Did it in a simple function, can add addslashes or stripslashes
    // if you want, but that should protect you from most things.
    function filterMePlox$string ){
         
    $string htmlentities$stringENT_QUOTES );
         
    $string mysql_real_escape_string$string );
    }

    $value filterMePlox($_POST['value']);

    $dsql="UPDATE `user` SET `status` = '$value' WHERE `id` = '$usrd[id]'";

    $dupdate=mysql_query($dsql) or die ("Sorry, something went wrong");  

    echo 
    $value


    www.fragme.co = a project.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •