Jump to content

Nu salveaza codul html in baza de date!

Go to solution Solved by LuciaNNN.,

Recommended Posts

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

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

Link to comment
Share on other sites

  • 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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.