Page 1 of 1

Storing Dom manipulation with PHP question

Posted: Tue Oct 08, 2013 7:20 pm
by taoist
Hello,
I have a simple Javascript client script that consist of an an HTML button and when clicked it creates new DOM nodes, each with their own ID per an incrementing counter.

When the user clicks the button I want each DOM node to be stored to mysql via PHP for later recall.

I'm not sure how to go about doing this.

DO I launch a php script in conjunction with each button click to store the dom element name/ID ? Or do I go about it another way?

Just looking for some direction here.

Thank you.

Re: Storing Dom manipulation with PHP question

Posted: Tue Oct 08, 2013 8:51 pm
by Christopher
taoist wrote:When the user clicks the button I want each DOM node to be stored to mysql via PHP for later recall.
If you want that to happen then you need the Javascript to make an Ajax call to a PHP script in the button click event handler.

Re: Storing Dom manipulation with PHP question

Posted: Thu Oct 10, 2013 2:55 am
by taoist
I have a block of code of which pushes a value to an array in Javascript. The problem I have now is getting this value to PHP and hence the database.

Javascript

Code: Select all


var temp = [];

$(function(){
	
	
	$('#orange-button').click(function(){
		$.ajax({
			type: 'GET',
			url: 'add.php',
			data: temp,                  // This is not correct ... HELP!
			success: function(){
				$('#success').html();
			}
		});
	});
	
	
});


PHP

Code: Select all

<?php
require_once 'connect.php';
?>

<?php
$con=mysqli_connect("localhost","root","root","instruments");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Create table
$sql="INSERT INTO synths (domID)
VALUES ({$temp})";                        // This is not correct ... HELP!

// Execute query
if (mysqli_query($con,$sql))
  {
  echo "Table persons created successfully";
  }
else
  {
  echo "Error creating table: " . mysqli_error($con);
  }
?>

Re: Storing Dom manipulation with PHP question

Posted: Fri Oct 11, 2013 9:06 am
by antorizz
in your PHP file, have you tried changing

Code: Select all

{$temp}
to

Code: Select all

{$_GET['temp']}
?