任何人都可以告诉我代码中有什么问题吗

时间:2018-08-06 09:32:08

标签: php mysqli

请让我知道这里出了什么问题。

出现此错误:

  

提交时请检查您的查询

        <?php

        if ( isset( $_POST[ 'submit' ] ) ) {
            if ( empty( $_POST[ 'subcat' ] ) ) {
                echo '<span style="color: red;"> Please Fill in the Category Name</span> ';
            } else {


                $subcat = $_POST[ 'subcat' ];


                $query = " insert into subcategory (scatname) values('$subcat')";
                $result = mysqli_query( $con, $query );

                if ( $result ) {
                    echo '<span style="color: green;">Category Added Successfully</span>';
                } else {
                    echo '  Please Check Your Query ';
                }
            }
        }

        ?>

        <form method="post" action="">
            <div class="form-group">
                <lable>Sub Category Name</lable>
                <input type="text" class="form-control" name="subcat"/>
            </div>
            <div class="form-group">
                <lable>Select Category</lable>
                <select class="form_control" name="cat">
                    <?php 

    $query="select * from category";
    $sql=mysqli_query($con,$query);
    if(mysqli_num_rows($sql)>0){
        while($row=mysqli_fetch_assoc($sql)){



    ?>
                    <option value="<?php echo $row['cid']; ?>">
                        <?php echo $row['catname']; ?>
                    </option>
                    <?php 
            }   
    }       
        ?>
                </select>
            </div>


            <div class="form-group">
                <button class="btn btn-primary" name="submit">Submit</button>

            </div>

        </form>
    </div>

</div>

1 个答案:

答案 0 :(得分:0)

查询失败,因为您没有转义字符串 if isinstance(mp_reduction_shape, int) or isinstance(mp_reduction_shape, float): self.mp_reduction_h = int(mp_reduction_shape) self.mp_reduction_w = int(mp_reduction_shape) elif isinstance(mp_reduction_shape, tuple) or isinstance(mp_reduction_shape, list): self.mp_reduction_h = int(mp_reduction_shape[0]) if len(mp_reduction_shape) == 1: self.mp_reduction_w = int(mp_reduction_shape[0]) else: self.mp_reduction_w = int(mp_reduction_shape[1]) else: self.mp_reduction_h = int(mp_reduction_shape[0]) self.mp_reduction_w = int(mp_reduction_shape[1])

$subcat

您可以在此处了解更多信息:
http://php.net/manual/en/mysqli.real-escape-string.php