单击php,ajax,mysql创建一个新的表行/用户

The html, and clicking the create div would redirect to an identical page, but would add a new row and increment the [text_edit_id] in the database. This is my table: http://imgur.com/KoNg1ju

<div class="saveChange" onclick="saveEdits()"></div>
<div class="cancelChange" onclick="cancelEdits()"></div>
<div class="create"></div>

<div id="edit" class="title textEditor">
    <span contenteditable="true" class="pageTitle one editable" id="bodyTitle"><?php echo $row['text_title']; ?></span>
    <p id="bodyText" class="editable" contenteditable="true"><?php echo $row['text_text']; ?></p>
</div>

When you save a change

function saveEdits() {
var title = $('.pageTitle').html();
var text = $('#bodyText').html();
    console.log(title + text);
    $.ajax({
      type: "POST",
      url: "functions/functions.php",
      data: { title: title, text: text }
    }).done(function( msg ) {
        console.log(msg);
    });
};

the functions.php

<?php 
$host = "localhost";
$username = "root";
$password = "root";
$db = "textedit";

$connection = mysqli_connect($host,$username,$password,$db);
if (!$connection) {
    die("Database connection failed: " . mysql_error());
}

$text_title = $_POST['title'];
$text_text = $_POST['text'];

$stmt = $connection->prepare("UPDATE data SET text_title = ?, text_text = ? WHERE text_edit_id = 1");
$stmt->bind_param('ss', $text_title, $text_text);
$stmt->execute();
?>
查看全部
doubi1713
doubi1713
2014/12/11 19:41
  • php
  • mysql
  • ajax
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复