0

can anyone let me know what the wrong thing here as i am not able to add subcategories to category

<div class="col-lg-4 mx-md-auto paper-card"> <?php

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

                        $subcat =clean($_POST[ 'subcat' ]);
    $query = "insert into subcategory values ('','$_POST[cat]','$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></div>

        <div class="col-lg-4 mx-md-auto paper-card"> <?php

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

                    $subcat =clean($_POST[ 'subcat' ]);
$query = "insert into subcategory values ('','$_POST[cat]','$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></div>

Edited by s_15

3
Contributors
8
Replies
54
Views
1 Week
Discussion Span
Last Post by JamesCherrill
0

opps noboday knows the error here... very strange

0

error is it just say please check query

and i am not getting what is wrong in the query

just need to add subcateogries to categories

0

Here's the other reason you may not be getting replies. Read the link I gave and the second "Composing a good question".
So far you have a dump and no questions. Questions should be in the form of a question followed by the question mark so it's clear what you are asking.

One more time. Read the link about "Composing a good question". Pare down the code to just what's needed and if some SQL database schema is needed to understand you have to share that as well.

Finally. Spend some time on grammer. Sentences should start with a capital letter and end with the usual period, question mark or !

0

Spend some time on grammer (sic). Sentences should start with a capital letter and end with the usual period, question mark or !

It's pretty obvious that English isn't s_15's first language. I doubt (s)he came here for a language lesson, and grammar shaming isn't what DaniWeb is for. So let's be tolerant of one another's English and concentrate on the actual reason for this topic.

Edited by JamesCherrill

1

@JC. I didn't intend to shame anyone. Let's hope they spend time on their composition of the question.

Votes + Comments
Agreed James Cherrill
0

i think getting help from here is usless as noboday want to help but just chatter here thinking to disable my account here as its useless that anyone will help :)

1

People here do want to help you, but the information you have provided is not sufficient. Did you take the time to check rproffitt's link in his first answer?

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.