繁体   English   中英

如何在MySQL数据库中存储div数据?

[英]How to store div data in Mysql db?

我是PHP新手。 我有一个使用多个内联文本编辑器的代码。 为了方便起见,我有一个链接JQuery Widgets内联文本编辑器对于每个文本编辑器,我都使用多个div。 现在我想将我的div数据存储在Mysql db中。 但我现在不知道如何在变量中获取div数据? 我只需要语法帮助我如何在mysql db中存储div数据

这是我的代码

<!DOCTYPE html>
<html lang="en">
<head>
    <title id='Description'>Notification Letter.</title>
    <link rel="icon" href="image/pacra_logo.png" type="image/png" sizes="16x16">
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../../scripts/demos.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdropdownbutton.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcolorpicker.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxwindow.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxeditor.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxtooltip.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script>
</head>
<body>
<script type="text/javascript">
    $(document).ready(function () {
        $('#editor1').jqxEditor({tools: 'bold italic underline | left center right'
        });            
        $('#editor2').jqxEditor({tools: 'bold italic underline | left center right'
        });            
        $('#editor3').jqxEditor({tools: 'bold italic underline | left center right'
        });            
        $('#editor4').jqxEditor({ 
        });                 
        $('#editor5').jqxEditor({tools: 'bold italic underline | left center right'
        });
        $('#editor6').jqxEditor({ 
        });
        $('#editor7').jqxEditor({tools: 'bold italic underline | left center right'
        });
        $('#editor8').jqxEditor({tools: 'bold italic underline | left center right'
        });
        $('#editor9').jqxEditor({tools: 'bold italic underline | left center right'
        });
        $('#editor10').jqxEditor({tools: 'bold italic underline | left center right'
        });
        $('#editor11').jqxEditor({
        });
    });
</script>
<div style="width: 30%; float:" contenteditable="true" id="editor1">
    <p> NL FY 15-147 (PSO-040515) </p>
</div>
</div>
<div style="clear: both;"></div>
<div style="margin-top: 10px; width: 800px; text-align:justify; font-family:'Times New Roman', Times, serif; font-size:14px" contenteditable="true" id="editor6">
    <p>This has reference to our communication and discussion with you and your team regarding rating of Pakistan State Oil Company Limited (PSO). We appreciate that PSO management has been forthcoming in providing all the requisite information. This has enabled PACRA in forming the right ration opinion.</p> 
</div>

的HTML

        <!DOCTYPE html>
        <html lang="en">
        <head>
            <title id='Description'>Notification Letter.</title>
            <link rel="icon" href="image/pacra_logo.png" type="image/png" sizes="16x16">
            <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
            <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
            <script type="text/javascript" src="../../scripts/demos.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxdropdownbutton.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxcolorpicker.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxwindow.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxeditor.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxtooltip.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script>
        </head>
        <body>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#editor1').jqxEditor({tools: 'bold italic underline | left center right'
                });            
                $('#editor2').jqxEditor({tools: 'bold italic underline | left center right'
                });            
                $('#editor3').jqxEditor({tools: 'bold italic underline | left center right'
                });            
                $('#editor4').jqxEditor({ 
                });                 
                $('#editor5').jqxEditor({tools: 'bold italic underline | left center right'
                });
                $('#editor6').jqxEditor({ 
                });
                $('#editor7').jqxEditor({tools: 'bold italic underline | left center right'
                });
                $('#editor8').jqxEditor({tools: 'bold italic underline | left center right'
                });
                $('#editor9').jqxEditor({tools: 'bold italic underline | left center right'
                });
                $('#editor10').jqxEditor({tools: 'bold italic underline | left center right'
                });
                $('#editor11').jqxEditor({
                });
            });
        </script>
    <script>
    <script>
$(document).ready(function(){
$("button").click(function(){
        $.ajax({
              url: "process.php", 
              data:{data:$("#editor6").html()},
              success: function(result){
            alert("success");
        }
    });
    });
});
</script>
    </script>
        <div style="width: 30%; float:" contenteditable="true" id="editor1">
            <p> NL FY 15-147 (PSO-040515) </p>
        </div>
        </div>
        <div style="clear: both;"></div>
        <div style="margin-top: 10px; width: 800px; text-align:justify; font-family:'Times New Roman', Times, serif; font-size:14px" contenteditable="true" id="editor6">
            <p>This has reference to our communication and discussion with you and your team regarding rating of Pakistan State Oil Company Limited (PSO). We appreciate that PSO management has been forthcoming in providing all the requisite information. This has enabled PACRA in forming the right ration opinion.</p> 
        </div>

保存这个

您应该编写一个jQuery AJAX来将数据发送到PHP文件(考虑到您可以使用Javascript / jQuery获得文本):

jQuery的

// put this in your <Script> in $(document).ready(... section

// This Line Gets The Text Of The Editor 
var textVariable = $("#editor6 p").text();

// This Part Sends The Data To The Defined PHP File And Returns The Result
$.post("TARGET_PHP_FILE.php", {TypedText: textVariable}, function(data, status){
    // Do Something With The Response
    // data: every thing that prints on php file
    // status: HTTP Response Code
    // For more Info: http://www.w3schools.com/jquery/ajax_post.asp
});

的PHP

// Your Text Is Available Like This:
$text = $_POST['TypedText'];

// Then You Can Store It In Database Like This:
if ($db = mysqli_connect($host, $user, $pass)) {
    // Connected to the server
    if ($select = mysqli_select_db($db, "DATABASE_NAME")) {
        // Selected the database
        $query = "Your Query";
        if ($result = mysqli_query($db, $query)) {
            // Query sent
            if (mysqli_affected_rows($db)) {
                echo "Done";

                mysqli_close($db);
            }else{
                echo "Fail";

                mysqli_close($db);
            }
        }else{
            echo "Query Not Sent";
        }
    }else{
        echo "Selection Failed";
    }
}else{
    echo "Connection Failed";
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM