// connect to database $servername = "localhost"; $username = "myusername"; $password = "mypassword"; $dbname = "mydatabase"; $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // prepare SQL query $name = $_POST["name"]; $email = $_POST["email"]; $phone = $_POST["phone"]; $sql = "INSERT INTO users (name, email, phone) VALUES ('$name', '$email', '$phone')"; // execute query if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "This code uses the MySQLi extension in PHP to connect to a MySQL database, prepare an SQL query to insert the user's details into a table called 'users', and execute the query. If the query is successful, it will display a message saying 'New record created successfully'. Otherwise, it will display an error message. The package library used in this example is the MySQLi extension, which is included in the PHP core. Other popular PHP database libraries include PDO, MySQL, and PostgreSQL.
" . $conn->error; } // close connection $conn->close();