Jump to content

Nu salveaza codul html in baza de date!


Go to solution Solved by LuciaNNN.,

Recommended Posts

Posted

Salut. Doresc sa fac un site builder cu tehnologia drag and Drop. Codul generat in html as dori sa l salvez in mysql. Am functia Java script pentru asta. 

cmdms.add('save-db', { 
    run: function (em, sender) {
        sender.set('active', true); //get full HTML structure after design 
        var InnerHtml =  editor.getHtml() + '<style>' + editor.getCss()  + '</style>';
        
        $.post("save.php", {html: InnerHtml}, 
        function (result) { 
           //action after save success 
            
        }); 
    }, 
});

si in save.php am

<?php   
require "login/dbconf.php";
$dbconn = mysqli_connect( $host, $username, $password, $db_name );
if (isset($_POST['html'])) { 
    $created = time(); 
    $sql2 = "INSERT INTO `members` SET `templates`  (html,created)  VALUES  ( '". $_POST['html'] ."','" . $created."');";
    $query2 = mysqli_query( $dbconn, $sql2 );
}



?>

E corecta sintaxa de la $sql2?  ce fac gresit?  

In tabelul members am o coloana numita "tamplates"

Daca ti-am fost de ajutor la acest topic apeasa pe FhiZsPe.png

  • Solution
Posted (edited)

Nu, nu este, in primul rand definesti INSERT, dar tu setezi ceva, syntaxa corecta este urmatoarea:

$sql2 = "INSERT INTO `TABEL` (COLOANA_1, COLOANA_2, COLOANA_x)  VALUES  ("Valoarea_1", "Valoarea_2", "Valoarea_x");";

iar cum ai folosit tu "SET", se va folosi astfel:

$sql2 = "UPDATE `TABEL` SET  `COLOANA_1` = "valoearea_1", `COLOANA_2` = "valoarea_2", `COLOANA_x` = "valoarea_x" WHERE `PRIMARY_KEY` = "x/y";";

Si probabil vei avea niste probleme cu salvarea textului HTML in db, asa ca iti recomand sa il salvezi intr-o coloana de tip TEXT si sa folosesi json_encode pentru al cripta si json_decode sa il decriptezi, asta daca nu ai deja o functie pentru asta si vrei tu sa o faci.

 

Daca ai discord, te astept pe server-ul meu de discord sa te mai ajut 😇 LINK

Edited by LuciaNNN.
  • Like 1

Filme: Click.

Contact: Steam

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.