0
<?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

Edited by TechySafi: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by TechySafi
1

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)

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.