How To Create Table Dynamically using Php MySQL Step By Step:-

Step 1) Create a folder in htdocs give the name as a table. open the folder and create a new file save it as db.php and copy the code to the db.php code.


$servername = "localhost";
$username = "root";
$password = "";
$dbname = "table";
$conn = new mysqli($servername, $username, $password, $dbname);
    echo "Connection Failed";

Step 2) Open a browser type http://localhost/phpmyadmin/ in the URL. Click on Create new database as give name table to the database and check the connection is successfully established or not.
After checking the connection Create a new file give name as table.php and copy the code of table.php and run the table.php file and pass a name to form which table you want to create and click on submit button after submit button see in PHPMyAdmin the table is created successfully


include "db.php";
$result = mysqli_query($conn,"SHOW TABLES LIKE '".$table_name."'");
if($result->num_rows == 1) {
        echo '<script language="javascript">';
        echo 'alert("Table exists, Please try again")';
        echo '</script>';
else {
    $table5 = "CREATE TABLE $table_name ( id INT(250) UNSIGNED AUTO_INCREMENT PRIMARY KEY,emp_name VARCHAR(200), salary VARCHAR(200),status tinyint(1) DEFAULT '1', date datetime)";
        echo '<script language="javascript">';
        echo 'alert("Table Successfully Created")';
        echo '</script>';
<!DOCTYPE html>
    <title>Create Automatic Table in php mysqli by Yourphpguru</title>
    <form action="" method="post" style="margin-top: 50px;margin-left: 70px;">
        <input type="text" name="table_name"><br/><br/>
        <input type="submit" name="submit" value="submit">

If Anyone Need Help or Some Error Occur Join this Group By Clicking on Link.
I Will Help You.

Whatsapp Group:-

Thank You


Leave a Reply

Your email address will not be published. Required fields are marked *