Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/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:UncaughtTypeError 函数更多(){ var MoreDetails=document.getElementById('MoreDetails'); MoreDetails.style.display=“block”; } 函数相同(){ var SameProduct=document.getElementById('SameProduct'); SameProduct.style.display=“block”; } init({选择器:'textarea'}); 插入产品 产品类型: 产品类别: 选择一个类别 产品品牌: 选择一个品牌_Javascript_Php - Fatal编程技术网

Javascript:UncaughtTypeError 函数更多(){ var MoreDetails=document.getElementById('MoreDetails'); MoreDetails.style.display=“block”; } 函数相同(){ var SameProduct=document.getElementById('SameProduct'); SameProduct.style.display=“block”; } init({选择器:'textarea'}); 插入产品 产品类型: 产品类别: 选择一个类别 产品品牌: 选择一个品牌

Javascript:UncaughtTypeError 函数更多(){ var MoreDetails=document.getElementById('MoreDetails'); MoreDetails.style.display=“block”; } 函数相同(){ var SameProduct=document.getElementById('SameProduct'); SameProduct.style.display=“block”; } init({选择器:'textarea'}); 插入产品 产品类型: 产品类别: 选择一个类别 产品品牌: 选择一个品牌,javascript,php,Javascript,Php,这是因为它document.getElementById('MoreDetails')不接收DOM元素,变量MoreDetails为null 您应该在id为MoreDetails的DOM elemenet之后调用函数more(),但您在之前调用它,因此无法获取此DOM元素。对more()和same()的调用发生在它们在DOM中引用的元素之前 将对more()和same()的调用移动到元素MoreDetails和SameProduct之后的某个位置 <script>

这是因为它
document.getElementById('MoreDetails')
不接收DOM元素,变量
MoreDetails
null

您应该在id为
MoreDetails
的DOM elemenet之后调用函数
more()
,但您在之前调用它,因此无法获取此DOM元素。

对more()和same()的调用发生在它们在DOM中引用的元素之前

将对more()和same()的调用移动到元素MoreDetails和SameProduct之后的某个位置

    <script>

    function more(){
        var MoreDetails = document.getElementById('MoreDetails');

        MoreDetails.style.display ="block";
    }

    function same(){
        var SameProduct = document.getElementById('SameProduct');

        SameProduct.style.display = "block";
    }
    </script>

    <!DOCTYPE HTML>
    <?php
        $con = mysqli_connect('localhost', 'root', '', 'test') or die("Cannot connect to datbase");
    //  $seller = $_SESSION['sellMail'];
    ?>
    <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
    <script>tinymce.init({ selector:'textarea' });</script> 

    <html>
    <head>

</head>
<body>

    <div id = "ProductForm">
        <form id="product" method="POST" enctype = "multipart/form-data" novalidate>
            <table align="center" width="750" border ="2">
                <tr align="center">
                    <td colspan="7"><h2>Insert Product</h2></td>
                </tr>

                <tr>
                    <td align="right"><b>Type of Product: </b></td>
                    <td>
                        <input list="text" name="type" placeholder = "Select a type" required>
                        <datalist id="text">
                            <?php
                                $run = mysqli_query($con, "Select * from typeproduct");
                                while($row = mysqli_fetch_array($run)){
                                    $type_title = $row['type_title'];
                                    echo "<option>$type_title</option>";
                                }
                            ?>
                        </datalist>
                    </td>
                </tr>

                <tr>
                    <td align="right"><b>Product Category: </b></td>
                    <td>
                        <select name = "prd_cat"  required>
                            <option>Select a Category</option>
                            <?php
                                $get_cat = "Select * from categories";
                                $run_cat = mysqli_query($con, $get_cat);
                                while($row = mysqli_fetch_array($run_cat)){
                                    $cat_id = $row['cat_id'];
                                    $cat_name = $row['cat_name'];

                                    echo "<option>$cat_name</option>";
                                }
                            ?>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td align="right"><b>Product Brand: </b></td>
                    <td>
                    <select name = "prd_brand" required>
                        <option>Select a Brand</option>
                            <?php
                                $get_brn = "Select * from brands";
                                $run_brn = mysqli_query($con, $get_brn);
                                while($row = mysqli_fetch_array($run_brn)){
                                    $brn_id = $row['brand_id'];
                                    $brn_name = $row['brand_title'];

                                    echo "<option>$brn_name</option>";
                                }
                            ?>
                        </select>


                    </td>
                </tr>

                <tr align="center">
                    <td><input type="submit" name="prdDetails" value="Insert Product"></td>
                </tr>
            </table>

        </form> 
        </div>      


                        <?php

                        if(isset($_POST['prdDetails'])){
                            $brand = $_POST['prd_brand'];
                            $type = $_POST['type'];
                            $cat = $_POST['prd_cat'];

                            $select = mysqli_query($con, "Select * from products where type = '$type' AND cat='$cat' AND brand = '$brand'");
                            if(mysqli_num_rows($select)==0){
                                echo "<script>more();</script>";
                            }else{
                                echo "<script>same();</script>";
                                $i=1;
                            ?>
                        <table id="SameProduct" style="display:none">
                            <tr>
                                <td>S.No</td>
                                <td>Product Image</td>
                                <td>Product Title</td>
                                <td>Product Description</td>
                                <td>Same Product</td>
                            </tr>

                            <?php
                            while($row = mysqli_fetch_array($select)){
                                    $img = $row['img'];
                                    $title = $row['title'];
                                    $desc = $row['p_desc'];
                                ?>
                                <tr>
                                    <td><?php echo $i;?></td>
                                    <td><img src="Product_image/<?php echo $img;?>"</td>
                                    <td><?php echo $title;?></td>
                                    <td><?php echo $desc;?></td>
                                    <td><button>Got the Same Product</button></td>
                                </tr>
                            <?php
                                $i++;
                            }

                            ?>
                            <tr>
                                <td><button>Product Not in list</button></td>
                            </tr>
                            </table>

                            <?php   
                            }

                            ?>

                            <?php

                        }                           
                            ?>



            <form method="POST" id="MoreDetails" enctype="multipart/form-data"> 
                <table style="display:none">

                <tr>
                    <td align="right"><b>Product Image: </b></td>
                    <td><input type="file" name="prd_img" required/></td>
                </tr>

                <tr>
                    <td align="right"><b>Product Price: </b></td>
                    <td><input type="text" name="prd_price" required/></td>
                </tr>

                <tr>
                    <td align="right"><b>Product Description: </b></td>
                    <td><textarea name="prd_desc" cols = "20" rows="10" required></textarea></td>
                </tr>

                <tr>
                    <td align="right"><b>Product Keywords: </b></td>
                    <td><input type="text" name="prd_keyword" required/></td>
                </tr>
                <tr align="center">
                    <td colspan="7"><input type="submit" name="insertPrd" id="insertPrd" value="Insert Now"/></td>
                </tr>
                </table></form>



</body></html>

<?php

    if(isset($_POST['insertPrd'])){
        $title = $_POST['prd_title'];
        $categ = $_POST['prd_cat'];
        $brand = $_POST['prd_brand'];
        $price = $_POST['prd_price'];
        $desc = $_POST['prd_desc'];
        $keywords = $_POST['prd_keyword'];

        $img = $_FILES['prd_img']['name'];
        $img_temp = $_FILES['prd_img']['tmp_name']; 

        move_uploaded_file($img_temp, "Product_image/$img");

        $insert_prd = "INSERT INTO products(cat, brand, title, price, p_desc, img, keyword, seller) VALUES ('$categ', '$brand', '$title', '$price', '$desc', '$img', '$keywords', '$seller')";

        $insert = mysqli_query($con, $insert_prd) or die("Cannot Insert");

        if($insert){
            echo "<script>alert('Product has been added');</script>";
            echo "<script>window.open('Seller.php','_self')</script>";
        }else{
            echo "<script>alert('Sorry! The Product cannot be added');</script>";
            echo "<script>window.open('Seller.php','_self')</script>";
        }
    }

?>