You create an html document (for example, index.php which contains html markup). In which you insert a form like this:
<form action="form.php" method="post"> <input type="text" name="login"> <input type="password" name="password"> <button>Отправить</button> </form>
You can find the description of the tags here (an intelligent resource for the start). In the action attribute you specify the path to the file (resource) to which to transfer data. In our case, this is a PHP file (located in the same directory). When you click on the button ( <button> ), the browser will send data to the server where our form.php will receive form.php . Attribute method="post" specify how to transfer.
On the server side, the data will fall into the $ _POST global array. You can pull them out like this:
<?php $login = htmlspecialchars (trim ($_POST['login'])); $password = htmlspecialchars (trim ($_POST['password'])); $password = md5 ($password);
We pull the data from the global array by the names of the inputs (remember name="login" and name="password" ) with minimal protection. Learn more about the features here . Password must hash.
To enter data into a table ( mysql ) you need to create it. I recommend at the current level of knowledge to create a table on a remote hosting where there is phpMyAdmin . It is done in it very simply, as well as the commands that are executed in the sql language are displayed. Suppose we have created a database and a users table in it. The table should have three columns: id , login , password . id unique user number, it needs to be made AUTO_INCREMENT so that when adding records the id new record increases by 1.
Now using PDO we will bring there the login and password of our new user.
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING ); $sql = "INSERT INTO users ( login, password ) VALUES ( :login, :password )"; $result = $db->prepare($sql); $result->bindParam(':login', $login, PDO::PARAM_STR); $result->bindParam(':password', $password, PDO::PARAM_STR); $result->execute();
We have not passed the id as it will automatically be recorded.
This is a very simple registration example. But the algorithm of actions is exactly the same when working with PHP.
input's with js, send all the data to the server, then you drop all the data into the right cells - meine