Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在MySQL中存储数据?_Javascript_Php_Html_Mysql - Fatal编程技术网

Javascript 如何在MySQL中存储数据?

Javascript 如何在MySQL中存储数据?,javascript,php,html,mysql,Javascript,Php,Html,Mysql,我正在编写一个脚本,可以使用mysql创建一个表并动态添加新行 此代码将包含两列值。我试图使用数组,但不知道如何继续 这是我的网页: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title> Dynamically </title> <style type="text/css"> form{ margin:

我正在编写一个脚本,可以使用mysql创建一个表并动态添加新行

此代码将包含两列值。我试图使用数组,但不知道如何继续

这是我的网页:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> Dynamically </title>
<style type="text/css">
    form{
        margin: 20px 0;
    }
    form input, button{
        padding: 5px;
    }
    table{
        width: 100%;
        margin-bottom: 20px;
        border-collapse: collapse;
    }
    table, th, td{
        border: 1px solid #cdcdcd;
    }
    table th, table td{
        padding: 10px;
        text-align: left;
    }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
        $(".add-row").click(function(){
            var name = $("#name").val();
            var email = $("#email").val();


            var markup = "<tr><td><input type='checkbox' name='record'></td><td>" + name + "</td><td>" + email + "</td></tr>";



        if ($('#name').val() == "") 
            {
            alert('Please Enter the Name');
            $('#name').focus();
            }
            else if 
             ($('#email').val() == "") 
            {
            alert('Please Enter the email');
            $('#email').focus();
            }
            else
            {
            $("table tbody").append(markup);


            $("#name").val("");
            $('#email').val('');
            $('#name').focus();

            }

        });

        // Find and remove selected table rows
        $(".delete-row").click(function(){
            $("table tbody").find('input[name="record"]').each(function(){
                if($(this).is(":checked")){
                    $(this).parents("tr").remove();
                }
            });
        });
    });    
</script>
</head>
<body>



        <input type="text" id="name" placeholder="Name">
        <input type="text" id="email" placeholder="Email Address">
        <input type="submit" class="add-row" value="Add Row">

    </form>
    <table>
        <thead>
            <tr>
                <th>Select</th>
                <th>Name</th>
                <th>Email</th>
            </tr>
        </thead>
        <tbody>
            <!--<tr>
                <td><input type="checkbox" name="record"></td>
                <td></td>
                <td></td>
            </tr>-->
        </tbody>
    </table>
    <button type="button" class="delete-row">Delete Row</button>
<button onclick="myFunction()">Click me</button>
</body> 
</html>   

您刚刚编写了某种客户端Javascript应用程序,例如在web浏览器中运行。 一种可能性是将该应用程序连接到一个服务器,该服务器公开一个API,从中请求某种类型的数据,并将其显示在应用程序表中

我建议以Angular及其英雄为例: 了解现代web应用程序开发。
下一步,您可以查看NodeJs,了解如何构建简单的服务器端API,以及如何将数据存储到MySQL或MongoDB中。

您的MySQL查询在哪里?php代码在哪里?请阅读如何使用ajax将数据发送到服务器。根据如何通过POST将表值转发到PHP中的指南,这个问题太广泛了。。。我不知道如何发布多个表行值。