goya.php file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Register</title>
</head>
<body>
<form action="" method="post">
User Name <input type="text" name="username"><br>
E-mail <input type="text" name="email"><br>
Password <input type="password" name="password"><br>
<input type="submit" value="Register" name="reg">
</form>
<?php
// create connection to DB
$connection = mysqli_connect("127.0.0.1", "root", "", "goya_db");
// checking the connection
if (mysqli_connect_errno()) {
die("DataBase connection1 fail..| ".mysqli_connect_error());
}else{
echo "DataBase Connection is Succesful";
}
if (isset($_POST["reg"])) {
// insert user data into database
$username = $_POST["username"];
$email = $_POST["email"];
$pass = $_POST["password"];
$data_insert_query = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$pass')";
$query_execute = mysqli_qurey($connection, $data_insert_query);
if ($query_execute) {
echo "one record is added";
}else{
echo "Inserting query is failed";
}
} // main if end
?>
</body>
</html>
<?php mysqli_close($connection) ?>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :
sqli file
-- phpMyAdmin SQL
-- https://www.phpmyadmin.net/
-- Host: 127.0.0.1
-- Server version: 10.1.28-MariaDB
-- PHP Version: 7.1.11
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
--
-- Database: `goya_db`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`Id` int(2) NOT NULL,
`username` varchar(20) NOT NULL,
`email` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`Id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `Id` int(2) NOT NULL AUTO_INCREMENT;
COMMIT;
1 ) create a db called "goya_db"
2) import "goya_db.sql" to mysqli server
3) run "goya.php"