SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Posting to database

    I've found this drag and drop script and it's brilliant but I can't seem to get it to update the results in the database.

    I've got this on the page:
    Code:
    <script language="Javascript">
    	$(document).ready(function() {
    			
    			 // Initialise the table
    			$('#images').tableDnD({
    				onDragClass: "drag",
    				onDrop: function(table, row) {	
    				  alert($.tableDnD.serialize());	
    					$.ajax({
    					 type: "POST",
    					 url: "http:/www.domain.com/new_site/admin/ajaxtest.php",
    					 data: "" + $.tableDnD.serialize(),
    					 success: function(html){
    					 }
    					});
    				}
    			});
    	});
    
    </script>
    the alert box does give the correct values, but when I call the ajaxtest.php page nothing happens.
    The ajaxtest.php page has this:
    Code:
    <?php
    include '../includes/db.php';
    $images[] = $_POST['images'];
    		$i = 0;
    		if(!empty($images[0])){
    			foreach($images as $value) {
    				foreach($value as $row){
    					$i++;
    					if($row != 'tHeader'){
    						$this->Image->set('id', $row);
    						$this->Image->set('order', $i);
    						$this->Image->save();
    					}
    				}
    			}
    		}
    $con = mysql_connect($host,$username,$password);
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    mysql_select_db($database, $con);
    $sql= sprintf("UPDATE `images` SET `order`='$i' WHERE `id`='$row'");
    if (!mysql_query($sql,$con))
    mysql_close($con)
    ?>
    I'm pretty sure the problem is with the $images[] = $_POST['images']; but of code, but I'm not sure exactly where and would be extremely grateful for any help.

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,994
    Mentioned
    100 Post(s)
    Tagged
    0 Thread(s)
    If you're uploading any files to a database, they get sent by the $_FILES array. Be sure to sanitize them when uploading, eg is the file size within the range allowed, is the image size in the range allowed, etc
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    If you're uploading any files to a database, they get sent by the $_FILES array. Be sure to sanitize them when uploading, eg is the file size within the range allowed, is the image size in the range allowed, etc
    It's not the actual files that are being uploaded just the order they're displayed in. Each image as an order field and that's all I'm trying to do is update that.


Tags for this Thread

Bookmarks

Posting Permissions

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