Member Avatar for TechySafi
<?php
                                    if (isset($_POST['submit'])) {
                                        if ($_POST['lang']=="") {
                                          echo "Dictionary name can't be emptry!";
                                        }
                                        else {
                                            $name=mysql_real_escape_string($_POST['lang']);
                                            include('db.php');
                                            [B]$check=mysql_query("SELECT *
                                            FROM information_schema.tables 
                                            WHERE table_name = '$name'");
                                            echo $count=mysql_num_rows($check);[/B]
                                            if ($count>0) {
                                                     echo "That dictionary name already exists!";
                                            }
                                            else {
                                                $go=mysql_query("CREATE TABLE IF NOT EXISTS $name (
                                            `id` int(11) NOT NULL AUTO_INCREMENT,
                                            `from` varchar(60) NOT NULL,
                                            `to` text NOT NULL,
                                            `by` varchar(40) NOT NULL,
                                            `status` int(1) NOT NULL,
                                            PRIMARY KEY (`id`)
                                            ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1");
                                            if($go)
                                            {
                                                echo "Dictionary name has been inserted into database!";
                                            }
                                            else
                                            {
                                                echo mysql_error()."Something went wrong!";
                                            }
                                            }
                                            
                                        }
                                    
                                    }
                                    [B]$check2=mysql_query("SELECT *
                                            FROM information_schema.tables 
                                            WHERE table_name ='eng2ben'");
                                            echo $count2=mysql_num_rows($check2);[/B]
                                            
                                    ?>

Just see the bold codes. When I hit submit button writting eng2ben, script echos 1 since that table already exists. Thats normal but see the next bold part, its still the same query but but it echos 0!!

Whats wrong? :D

I think it's because your db connection code is only being called in the first else condition.

Move include('db.php'); near the top of the file (outside of any if/else condition)

Member Avatar for TechySafi

How stupid I was.....thats why sometimes we should take a break the looking through the code again :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.