php creae a table with id username email password and reg_date
- User
php creae a table with id username email password and reg_date
- Assistant
To create a table with id, username, email, password, and reg_date columns in PHP, you can use the following code:
code// connect to database $conn = mysqli_connect('localhost', 'username', 'password', 'database_name'); // check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } // create table $sql = "CREATE TABLE users ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, username VARCHAR(30) NOT NULL, email VARCHAR(50) NOT NULL, password VARCHAR(50) NOT NULL, reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )"; if (mysqli_query($conn, $sql)) { echo "Table users created successfully"; } else { echo "Error creating table: " . mysqli_error($conn); } // close connection mysqli_close($conn);