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.
Storing Dom manipulation with PHP question
Moderator: General Moderators
- 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
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.taoist wrote:When the user clicks the button I want each DOM node to be stored to mysql via PHP for later recall.
(#10850)
Re: Storing Dom manipulation with PHP question
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
PHP
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
in your PHP file, have you tried changing
to
?
Code: Select all
{$temp}Code: Select all
{$_GET['temp']}