0

This code is for a exercise of php and database.
If i write database and query in the text and click submit, then it have to show the result of query execution. but it doesn't work.

But as i think, there is no problem with syntax. What is the problem of this code?

<!DOCTYPE html>
<html>
    <head>

    </head>


    <body>
        <form action="lab.php" method="post">

            DB name : <input type="text" name="dbname"> 
            DB query : <input type="text" name="query"> 
            <input type="submit">


        </form>
        <?php
        $dbname = $_GET["dbname"];
        $query = $_GET["query"];?>

        <?php
        $db = new PDO("mysql:dbname=.".$dbname, "root", "root");
        $rows = $db->query($query);
        foreach($rows as $row) {
        ?>
        <?php foreach($row as $col){?>
         <li><?= $col ?> </li>

        <?php
            }?>

        <?php
            }?>

     </body>

</html>
Ben Kwon
  • 21
  • 2