0

I'l looking for how to save contenteditable to my sql DB.

I have something like this:

 echo '<td contenteditable="true" onblur="saveToDatabase" id="regist" style="background-color:'.$row['regist_color'].'" >'.$row['regist'].'</td>'

I don't know ho to send this information to this url with onblur="function" :

<?php
include 'db.php';

$id=$_POST['id'];

$sql = "UPDATE minichat SET  
regist='".$_POST['regist']."'  WHERE id=".$_POST['id'];

if (mysqli_query($conn, $sql)) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . mysqli_error($conn);
 }

 ('location:index.php');
mysqli_close($conn);
?>
Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
scunja
  • 37
  • 6
  • 2
    [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)*** Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard Jul 11 '17 at 15:42
  • https://api.jquery.com/jQuery.post/ –  Jul 11 '17 at 15:44
  • Ajax maybe, something with JSON – ArtisticPhoenix Jul 11 '17 at 15:48
  • You need to use AJAX requests to send information to your PHP script – Dennis de Best Jul 11 '17 at 15:48

0 Answers0