Please tell me how to make a user registration on your site. I am a beginner, interested in logic and technologies used.

For example, I understand that the form itself is HTML. The appearance of the form is CSS. The verification of form fields is either CSS or JS.

but I don't understand what's next?

how to save data from the form? Is it js or what are the options? how to transfer data? is it ajax or what other options are there? how and where to save data? is it sql or mongo db?

please help us understand the process that understand where to dig to implement registration on the site and save user data to the database.

Closed due to the fact that the question is too general for the participants Grundy , AK , Air , Stepan Kasyanenko , 0xdb Jan 22 at 9:15 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • If very briefly: When you click "register", you take all the data from the input 's with js, send all the data to the server, then you drop all the data into the right cells - meine
  • what sends the data to the server? and what interacts with the database? - Big D
  • do you have a server node? usually to a php or c # server (most common) - Sasuke
  • You have the code here show - Sasuke
  • @BigD, requests, ajax, fetch, xmlh, depending on what your server is. python, node, php, c #? - meine

1 answer 1

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.

  • Thanks for the detailed answer, I think it will be useful to many people like me =) - Big D
  • @BigD importantly, that you understand it. - doox911