tidak bisa input data ke database

saya mencoba menggunakan grapesjs dari github semacam website builder gitu. Saya ingin save contentnya tapi data tidak mau masuk database. ini kodingannya

ini yang diindex.php

 cmdm.add('save-db', {
    run: function(em, sender){
      sender && sender.set('active', true);
      //get full HTML structure
      var InnerHtml = editor.getHtml() + '<style>' + editor.getCss() + '</style>';
      $.post("save.php", {html: InnerHtml}, function(result){
        editor.store();
      })
      //turn off the button

    }
  });

ini yang di save.php

 <?php

session_start();

include_once "../login/dbconf.php";

$conn = new mysqli($host, $username, $password, $db_name);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

if(isset($_POST['html'])){

    $created = time();
    $sql = "INSERT INTO templates (html, created) VALUES ('$_POST[html]', '$created')";

    if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
    } else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

}

data tidak bisa masuk ke table templates tapi kalo pake developer tools itu ada tulisan stored > object, itu artinya apa ya

avatar clarisa
@clarisa

8 Kontribusi 0 Poin

Diperbarui 6 tahun yang lalu

2 Jawaban:

Coba ubah seperti ini :


if(isset($_POST['html'])){

    $created = time();
    $sql = "INSERT INTO templates (html, created) VALUES ('$_POST[html]', '$created')";

    mysqli_query($conn, $sql);
    echo "New record created successfully";
header("location:index.php");

}

else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

klo masih ga bisa coba mysqli nya ubah jadi mysql

klo $stored->object itu sama kaya php oop atau framework laravel dari OOP style,

ini kutipan di internet : Sebagai contoh, di dalam procedural style mysqli, terdapat fungsi mysqli_query(), sedangkan dalam OOP style mysqli, menggunakan method $mysqli->query().

avatar nanto88
@nanto88

122 Kontribusi 56 Poin

Dipost 6 tahun yang lalu

tetep gabisa

saya ubah kodingannya jadi gini di save.php

 <?php

session_start();

include_once "../login/dbconf.php";

$conn = mysqli_connect($host, $username, $password, $db_name);

if (!$conn){
    die("Connection failed: ".mysqli_connect_error());
}

if(isset($_POST['html'])){

    $created = time();
    $sql = "INSERT INTO templates (html, created) VALUES ('$_POST[html]', '$created')";

    if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
    header("location: index.php")
    } else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

}

dan ini tampilan plugin yang ada diindexnya

 cmdm.add('save-db', {
    run: function(em, sender){
      sender.set('active', false);
      //get full HTML structure
      var InnerHtml = editor.getHtml() + '<style>' + editor.getCss() + '</style>';
      $.post("save.php", {html: InnerHtml}, function(result){
        // code
      })
      //turn off the button
      editor.store();
    }
  });

tetep ga masuk ke database di table templates, ini tampilan di developer tools chrome

avatar clarisa
@clarisa

8 Kontribusi 0 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban