Fix my AJAX Drag and Drop Code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ameshkin

    Fix my AJAX Drag and Drop Code

    Hi,
    I've been working on a drag drop system and something happened when I
    tried to switch the code from a working model to one with another
    database. The drag drop still works, but the informatin in the
    database is still not updating. I kind of got aggravated and could not
    figure out the problem with my 4 months of PHP experience.

    If anyone would like to look over the code, then go tot his URL and get
    in touch with me if interested!

    Thank You




  • noone

    #2
    Re: Fix my AJAX Drag and Drop Code

    ameshkin wrote:[color=blue]
    > Hi,
    > I've been working on a drag drop system and something happened when I
    > tried to switch the code from a working model to one with another
    > database. The drag drop still works, but the informatin in the
    > database is still not updating. I kind of got aggravated and could not
    > figure out the problem with my 4 months of PHP experience.
    >
    > If anyone would like to look over the code, then go tot his URL and get
    > in touch with me if interested!
    >
    > Thank You
    >
    >
    > http://www.mytuneslive.com/DragDrop/...ylistOrder.php
    >[/color]

    I don't play that game. give us a code snippet that you feel is not
    working. My first guess is that you have a problem in your database
    connection code... make sure you are checking the return status from ALL
    database calls and handle the error at that point. if you don't, your
    transaction integrity may not produce the results you expect and then
    you have orphan data and your database becomes useless as your db is
    only as good as the data in it...

    Comment

    • R. Rajesh Jeba Anbiah

      #3
      Re: Fix my AJAX Drag and Drop Code

      ameshkin wrote:[color=blue]
      > Hi,
      > I've been working on a drag drop system and something happened when I
      > tried to switch the code from a working model to one with another
      > database. The drag drop still works, but the informatin in the
      > database is still not updating. I kind of got aggravated and could not
      > figure out the problem with my 4 months of PHP experience.
      >
      > If anyone would like to look over the code, then go tot his URL and get
      > in touch with me if interested!
      >
      > http://www.mytuneslive.com/DragDrop/...ylistOrder.php[/color]

      On Ajax request, it is throwing Notice: Undefined variable: us in
      /var/www/vhosts/mytuneslive.com/httpdocs/DragDrop/ChangePlaylistO rder.php
      on line 52

      FWIW, I see lot of people leaning towards xajax; and hope better
      framework will come soon.

      --
      <?php echo 'Just another PHP saint'; ?>
      Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

      Comment

      • ameshkin

        #4
        Re: Fix my AJAX Drag and Drop Code

        Thanks,
        I just finally changed my server last night so that it showed me the
        errors. This is a new dedicated server from godaddy. As far as teh
        variable us, i dont know why its not working. It has a value clear as
        day, but I will figure this out.

        Comment

        • ameshkin

          #5
          Re: Fix my AJAX Drag and Drop Code

          I don't understand whats wrong. I'm very new to PHP and this is
          probably something very easy. This is the code.

          <?php
          $us = "ameshkin69 ";
          mysql_connect(' localhost', 'playlist', 'amir18');
          mysql_select_db ('playlist');
          function parse_data($dat a)
          {
          $containers = explode(":", $data);
          foreach($contai ners AS $container)
          {
          $container = str_replace(")" , "", $container);
          $i = 0;
          $lastly = explode("(", $container);
          $values = explode(",", $lastly[1]);
          foreach($values AS $value)
          {
          if($value == '')
          {
          continue;
          }
          $final[$lastly[0]][] = $value;
          $i ++;
          }
          }
          return $final;
          }

          function update_db($data _array, $col_check)
          {

          foreach($data_a rray AS $us => $items)
          {
          $i = 0;
          foreach($items AS $item)
          {
          $item = mysql_escape_st ring($item);
          $us = mysql_escape_st ring($us);

          mysql_query("UP DATE RecentUploads SET `order` = '$i' WHERE
          `User` = '$us'");
          $i ++;
          }
          }
          }

          // Lets setup Sajax
          require_once('S ajax.php');
          sajax_init();
          // $sajax_debug_mo de = 1;

          function sajax_update($d ata)
          {
          $data = parse_data($dat a);
          update_db($data , "AND (`User` = '$us')");
          return 'y';
          }

          sajax_export("s ajax_update");
          sajax_handle_cl ient_request();



          echo $data;
          ?>

          <style type="text/css">

          #box {
          width: 300px;
          float: left;
          margin-left: 5px;
          }

          body {
          background: #FCFEF4 repeat-x;
          margin: 10px 10px 10px 10px;
          font-family: Arial, Verdana, Helvetica;
          font-size: 76%;
          color: #3F3F3F;
          text-align: left;
          }

          h2 {
          color: #7DA721;
          font-weight: normal;
          font-size: 14px;
          margin: 20px 0 0 0;
          }

          br {
          clear: left;
          }
          </style>

          <link rel="stylesheet " href="lists.css " type="text/css">
          <script language="JavaS cript" type="text/javascript"
          src="coordinate s.js"></script>
          <script language="JavaS cript" type="text/javascript"
          src="drag.js"></script>
          <script language="JavaS cript" type="text/javascript"
          src="dragdrop.j s"></script>
          <script language="JavaS cript" type="text/javascript"><!--
          <?php
          sajax_show_java script();
          ?>
          function confirm(z)
          {
          window.status = 'Playlist Updated';
          }

          function onDrop() {
          var data = DragDrop.serDat a('g2');
          x_sajax_update( data, confirm);
          }

          window.onload = function() {

          list = document.getEle mentById("box") ;
          DragDrop.makeLi stContainer( list, 'g2' );
          list.onDragOver = function() { this.style["background "]
          = "#EEF"; };
          list.onDragOut = function() {this.style["background "] =
          "none"; };
          list.onDragDrop = function() {onDrop(); };

          };

          function getSort()
          {
          order = document.getEle mentById("order ");
          order.value = DragDrop.serDat a('g1', null);
          }

          function showValue()
          {
          order = document.getEle mentById("order ");
          alert(order.val ue);
          }
          //-->
          </script></head>

          <body>

          <br />



          <ul id="box" class="sortable boxy">
          <?php


          $r = mysql_query("SE LECT * FROM `RecentUploads` WHERE `User` = '$us'
          ORDER BY `UploadDate` ASC");
          while($rw = mysql_fetch_arr ay($r))
          {
          echo '<li id="'.$rw['FileName'].'">'.$rw['FileName'].'</li>';
          }
          ?>
          </ul>



          </body></html>

          Comment

          • no-1

            #6
            Re: Fix my AJAX Drag and Drop Code

            is $us a "POST/GET" variable? Global_variable s are turned OFF (as they
            should be) and you should change the code to $_POST['us'] or use this
            at the beginning of your script:

            if (!empty($_GET))
            {
            extract($_GET);
            }
            else if (!empty($HTTP_G ET_VARS))
            {
            extract($HTTP_G ET_VARS);
            }

            if (!empty($_POST) )
            {
            extract($_POST) ;
            }
            else if (!empty($HTTP_P OST_VARS))
            {
            extract($HTTP_P OST_VARS);
            }


            Using a database for your username/pwd, you need to be very careful to
            make sure that the data received does not include sql-injection (sear
            google for scripting that can help prevent it....)

            Comment

            • ameshkin

              #7
              Re: Fix my AJAX Drag and Drop Code

              Hi,
              Whats a sql-injection. lol

              I'll just google it. I'm having someone help me look at this code.
              But yes, the new dedicated server does have global variables turned
              off. The old one did not, and I think this is causing more trouble in
              other places too.

              Comment

              Working...