Storing Dom manipulation with PHP question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
taoist
Forum Newbie
Posts: 2
Joined: Tue Oct 08, 2013 7:08 pm

Storing Dom manipulation with PHP question

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Storing Dom manipulation with PHP question

Post 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.
(#10850)
taoist
Forum Newbie
Posts: 2
Joined: Tue Oct 08, 2013 7:08 pm

Re: Storing Dom manipulation with PHP question

Post 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);
  }
?>
antorizz
Forum Newbie
Posts: 8
Joined: Sat Nov 03, 2012 12:03 pm

Re: Storing Dom manipulation with PHP question

Post by antorizz »

in your PHP file, have you tried changing

Code: Select all

{$temp}
to

Code: Select all

{$_GET['temp']}
?
Post Reply