Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving Data to Database

Status
Not open for further replies.

likelylad

IS-IT--Management
Jul 4, 2002
388
GB
I have this drag and drop application and would like to save the location to a database.

When I hit the save button all the correct information is sent to the following.

Code:
<div id="saveContent"></div>

How do I get the content sent to the <div> into a database.

Thanks in advance for any help received.
 
Hi

Like this ?
JavaScript:
[b]var[/b] http[teal]=[/teal][b]new[/b] [COLOR=darkgoldenrod]XMLHttpRequest[/color][teal]()[/teal]
http[teal].[/teal][COLOR=darkgoldenrod]open[/color][teal]([/teal][green][i]'POST'[/i][/green][teal],[/teal][green][i]'/save/whatever'[/i][/green][teal],[/teal][b]false[/b][teal])[/teal]
http[teal].[/teal][COLOR=darkgoldenrod]send[/color][teal]([/teal][green][i]'data='[/i][/green][teal]+[/teal][COLOR=darkgoldenrod]escape[/color][teal]([/teal]document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'saveContent'[/i][/green][teal]).[/teal]innerHTML[teal]))[/teal]


Feherke.
 
I know that this is a stupid question but where does this bit of code go?
Below I have put the function that is called when the save button is hit

Code:
	function saveDragDropNodes()
	{
		var saveString = "";
		var uls = dragDropTopContainer.getElementsByTagName('UL');
		for(var no=0;no<uls.length;no++){	// LOoping through all <ul>
			var lis = uls[no].getElementsByTagName('LI');
			for(var no2=0;no2<lis.length;no2++){
				if(saveString.length>0)saveString = saveString + ";";
				saveString = saveString + uls[no].id + '|' + lis[no2].id;
			}	
		}		
		var formattedString = saveString.replace(/;/g,';<br>');
		document.getElementById('saveContent').innerHTML = formattedString;
			
	}
 
OK I have got it half working

The function is now

Code:
    function saveDragDropNodes()
    {
        var saveString = "";
        var uls = dragDropTopContainer.getElementsByTagName('UL');
        for(var no=0;no<uls.length;no++){    // LOoping through all <ul>
            var lis = uls[no].getElementsByTagName('LI');
            for(var no2=0;no2<lis.length;no2++){
                if(saveString.length>0)saveString = saveString + ";";
                saveString = saveString + uls[no].id + '|' + lis[no2].id;
            }    
        }        
        var formattedString = saveString.replace(/;/g,';<br>');
        document.getElementById('saveContent').innerHTML = formattedString;


var http=new XMLHttpRequest()
http.open('POST','sendtodatabase.php',false)
http.send('data='+escape(document.getElementById('saveContent').innerHTML)            
    }

However on my PHP page, how do I grab the data?
 
I am using firebug and I can see that post is sending the following

data=Product%20Training%7Callitems%7CFirstname%20Secondname%20%3B%3Cbr%3EProduct%20Training%7Callitems%7CFirstName%20FirstName

In my PHP page I am using

Code:
$data=$_POST[data];

[i]send to database code[/i]

But the variable is not being populated in the database
 
Code:
$test=$_POST['data'];
include "connect_to_database.php";
mysqli_select_db($db,"database");
$result = mysqli_query($db,"Insert Into mytable (Field1,Field2,Field3,Field4) Values ('data','$test','data','data')");

In the table, Field1/Field3/Field4 are populated with data but Field2 is empty
 
The only way that I could get it to work is by the following

Code:
http.open('POST','sendtodatabase.php?data='+formattedString,false);

 
Hi

Then the length of savable text is limited by the URL's length. See the ( somehow outdated ) [URL unfurl="true"]WWW FAQs: What is the maximum length of a URL?[/url] article on Boutell.com.

By the way, now I observed that you had a syntax error in your post at 1 Apr 10 8:58 :
Code:
http[teal].[/teal][COLOR=darkgoldenrod]send[/color][teal]([/teal][green][i]'data='[/i][/green][teal]+[/teal][COLOR=darkgoldenrod]escape[/color][teal]([/teal]document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'saveContent'[/i][/green][teal]).[/teal]innerHTML[teal])[/teal][highlight][teal])[/teal][/highlight]

Feherke.
 
Thanks, it was a copy and paste error.

You don't see any thing else wrong that meant I wouldn't have to send it across the url?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top