使用javascript和jQuery在MySql中从一个表向另一个表插入值

使用javascript和jQuery在MySql中从一个表向另一个表插入值,javascript,php,jquery,mysql,forms,Javascript,Php,Jquery,Mysql,Forms,我试图从MySql中的表'parents'中插入3个值到表'children'。其中一个名为“代码”的值插入得非常完美。但是,我无法插入另外两个“电子邮件”和“网站”。当我将它们添加到javascript代码中时,它只插入“code”3次。有人能帮我吗?以下是仅将“代码”字段从父项插入到子项的代码: $("a#reply").one("click", function() { var comCode = $(this).attr("

我试图从MySql中的表'parents'中插入3个值到表'children'。其中一个名为“代码”的值插入得非常完美。但是,我无法插入另外两个“电子邮件”和“网站”。当我将它们添加到javascript代码中时,它只插入“code”3次。有人能帮我吗?以下是仅将“代码”字段从父项插入到子项的代码:

$("a#reply").one("click", function() {
        var comCode = $(this).attr("name");
        var parent = $(this).parent();

        parent.append("<br /><form id='reply-form-toggle' action='' method='post'><input type='text' name='user' placeholder='Your Name *' required='required' required><br><textarea class='form-text' name='new-reply' id='new-reply' placeholder='Your Reply' required='required'></textarea><input type='hidden' name='code' value='"+comCode+"' /><span style='float: right;'><a onclick='hideReplyForm();'>Cancel</a>&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' class='form-submit' id='form-reply' name='new_reply' value='Reply' /></span></form>");
    });
$(#回复”).one(“单击”,函数(){
var comCode=$(this.attr(“名称”);
var parent=$(this.parent();
parent.append(“

取消”); });
以下是插入代码:

<?php
    // new comment
    if(isset($_POST['new_comment'])) {
        $new_com_name = $_SESSION['user'];
        $new_com_email = $_POST['email'];
        $new_com_website = $_POST['website'];
        $new_com_text = $_POST['comment'];
        $new_com_date = date('Y-m-d H:i:s');
        $new_com_code = generateRandomString();
                
                // automatically inserts the ESCAPE CHARACTER - Now content will insert into database with single quote character
                $new_com_name = addslashes($new_com_name);
                $new_com_email = addslashes($new_com_email);
                $new_com_website = addslashes($new_com_website);
                $new_com_text = addslashes($new_com_text);
                
        if(isset($new_com_text)) {
            $sql = "INSERT INTO `parents` (`user`, `email`, `website`, `text`, `date`, `code`) VALUES ('$new_com_name', '$new_com_email', '$new_com_website', '$new_com_text', '$new_com_date', '$new_com_code')";
                        $result=$dbCon->query($sql);
                        
                        if ($result === TRUE) {
                            echo "<script type='text/javascript'>alert('Thank you for your comment! We will review it and hopefully approve it within 24 hours.');</script>";
                        }else{
                            echo "<script type='text/javascript'>alert('Your comment has not been submitted.');</script>";
                        }
        }
        header("Location: ");
    }
    // new reply
    if(isset($_POST['new_reply'])) {
        $new_reply_name = $_SESSION['user'];
        $new_reply_email = $_POST['email'];
        $new_reply_website = $_POST['website'];
        $new_reply_text = $_POST['new-reply'];
        $new_reply_date = date('Y-m-d H:i:s');
        $new_reply_code = $_POST['code'];
                
                // automatically inserts the ESCAPE CHARACTER - Now content will insert into database with single quote character
                $new_reply_name = addslashes($new_reply_name);
                $new_reply_email = addslashes($new_reply_email);
                $new_reply_website = addslashes($new_reply_website);
                $new_reply_text = addslashes($new_reply_text);
                
        if(isset($new_reply_text)) {
            $sql = "INSERT INTO `children` (`user`, `par_email`, `par_website`, `text`, `date`, `par_code`) VALUES ('$new_reply_name', '$new_reply_email', '$new_reply_website', '$new_reply_text', '$new_reply_date', '$new_reply_code')" or die(mysqli_error());
                        $resultReply=$dbCon->query($sql);
                        
                        if ($resultReply === TRUE) {
                            echo "<script type='text/javascript'>alert('Thank you for your reply! We will review it and hopefully approve it within 24 hours.');</script>";
                        }else{
                            echo "<script type='text/javascript'>alert('Your reply has not been submitted.');</script>";
                        }
        }
        header("Location: ");
    }
?>

请包含所有相关代码。向我们展示如何进行插入以及如何将参数传递给执行插入的函数。我尝试将“var comEmail=$(this).attr(“name”);”和“var comWebsite=$(this).attr(“name”);”添加到函数中,但没有用。这些值是通过MySql查询插入到php文件中的。请向我们展示实际执行插入的php代码以及调用该函数的代码片段。我们无法帮助您调试到目前为止您提供给我们的信息。请包括所有相关代码。向我们展示如何进行插入以及如何将参数传递给执行插入的函数。我尝试将“var comEmail=$(this).attr(“name”);”和“var comWebsite=$(this).attr(“name”);”添加到函数中,但没有用。这些值是通过MySql查询插入到php文件中的。请向我们展示实际执行插入的php代码以及调用该函数的代码片段。到目前为止,我们无法根据您提供的信息帮助您调试。