tags:

views:

61

answers:

2

Hello eveybody, I'm using jQuery + PHP + MySQL My problem is how to save for example this div in my MySQL database using an Ajax call with jQuery to PHP.

PS. i know how to send an Ajax call with jQuery to PHP and save variables from this call to MySQL.

<div id="id-aaa"> Les ordinateurs, eux, comme on l’a vu, ont un dispositif physique fait pour stocker (de multiples façons) des informations binaires. Alors, lorsqu’on 
  représente une information stockée par un ordinateur, le plus <span id="99" value="simple est 
  d’utiliser " style="color: black; font-size: 14px; font-weight: bolder;">simple est 
  d’utiliser </span>un système de représentation à deux chiffres les fameux 0 et 1. 
  Mais une fois de plus, je me permets d’insister, le choix du 0 et du 1<font id="annotation n°=2" value=" est 
  une pure convention" style="background-color: rgb(255, 255, 0);"> est 
  une pure convention</font>, et on aurait pu <font id="annotation n°=1" value="choisir n’importe " style="border-bottom: medium solid rgb(51, 255, 51);">choisir n’importe </font>quelle autre paire de 
  symboles à leur place. 
</div>
+1  A: 

Use the php mysql formatter.

assume this is ur variable $yourContent

convert it using mysql_real_escape_string($yourContent) function

Muneer
Thank you for you help i will try this function.
access2008
+3  A: 
var div_contents = $("#id-aaa").html();
$.post('myscript.php", { contents: div_contents });

This sends the contents of the div to the PHP script myscript.php.

myscript.php will have code like this.

// Using MySQL lib here, as it's most widely recognised
// Replace with MySQLi functions/object if you prefer
$con = mysql_connect($host, $username, $password);
mysql_select_db($database, $con);

$div = mysql_real_escape_string($_POST['contents']); // Make sure to clean the
                                                     // data before putting SQL

$sql = "INSERT INTO divs (contents) VALUES ('{$div}')";
$query = mysql_query($sql, $con);
if($query) {
     // Success!
} else {
     // Failure :(
}
Macha
Have i need to use mysql_real_escape_string() function in the reverse when tryign to retrieve this div content from my database and send it to other PHP script to append in <div id=recover>
access2008
You do not need to call it on data coming out of the database, only on data going into the database. I recommend you read up on SQL injections to find out why you need the function, and what it does.
Macha
Thank you for you replies.I will try this function.
access2008