We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8895
    • 76 Posts
    hi guys

    im tryin to make a rating snippet, but for sum reason the db update wont work =/

    buildup:
    ive got a snippet in modx which creates a list of buttons (1-10 = for the ratings),
    these call up a js function that calls up the rate.php in assets/snippets/rating
    and that file looks like this (untill now):

    	$id = $_REQUEST['id'];
    	$rating = $_REQUEST['action'];
    
    
    	$fields = array(
    			"rating" => $rating,
    			"ratings" => 1
    			);
    echo "bla";
    	$modx->db->update($fields, "media", "media_id = '$id'");
    echo "blabla";
    


    now here i get the 1st echo ’bla’ but the second ’blabla’ does not show.
    as far as i can tell, it has something to do with the update.

    can some one help me out here?

    thank you tons!!
      • 16732
      • 592 Posts
      Hi,

      Your rate.php file is not directly included in your snippet, so to take adventage of the MODx API you have 2 options :

      Old one :

      Upload the modxapi.php file and include it in your rate.php like this :

      $path =  'homepages/www/your site diectory/';  //absolute path
      include_once($path.'modxapi.php');
      
      $modx = new MODxAPI();
      // connect to db and load settings
      $modx->connect();
      $modx->getSettings();  
      


      New one (In 0961 or if you are running a 096 edit your index.php and comment the exit on line 130) :


      $path = ’homepages/www/your site diectory/’; //absolute path
      include_once($path.’index.php’);


      Hope that helps
        • 8895
        • 76 Posts
        thank you for your help..

        i updated modx to the actual version and edited the index.php as you told me to.
        now ive got the following in my rate.php:

        echo "start";
        
        $path =  "/hsphere/local/home/ri169/chaoticclips";
        include_once($path.'index.php')
        
        
        	$id = $_REQUEST['id'];
        	$rating = $_REQUEST['action'];
        
        
        	$fields = array(
        			"rating" => $rating,
        			"ratings" => 1
        			);
        echo "bla";
        	$modx->db->update($fields, "media", "media_id = '$id'");
        echo "blabla";
        


        now i dont even get the echo’s (not even the start echo) and it desnt do the db update either.
        the update syntax should work, tried it in a internal snippet and it did the update.

        if this should be too much gibberish, wouldnt it also be possible to call an internal snippet from
        the js and send it 2 variables?
          • 16732
          • 592 Posts
          I don’t know if it can be that but an ; is missing at the end of your include line
          include_once($path.'index.php')


          If it still not working try to add define(’MODX_API_MODE’, true); at the top of your script :

          define('MODX_API_MODE', true);
          $path =  "/hsphere/local/home/ri169/chaoticclips";
          include_once($path.'index.php');
          

            • 8895
            • 76 Posts

            ok, its looking a bit better:

            echo "1";
            
            define('MODX_API_MODE', true);
            $path =  "/hsphere/local/home/ri169/chaoticclips.com";
            include_once($path.'index.php');
            
            echo "2";
            
            	$id = $_REQUEST['id'];
            	$rating = $_REQUEST['action'];
            
            
            	$fields = array(
            			"rating" => $rating,
            			"ratings" => 1
            			);
            echo "3";
            
            	$dbupdate = $modx->db->update($fields, "media", "media_id = '$id'");
            
            echo " -> ";
            echo $dbupdate;
            


            i get the echos 1, 2 and 3 but not the one after the db update =(
              • 8895
              • 76 Posts
              it works!

              forgot the / at the end of the path
              now it works fine =)

              thanks a lot mate!