<?php $db = mysqli_connect("localhost" , "root" , "" , "reg") or die ("DataBase Erorr"); ?> <!DOCTYPE html> <html lang="ru"> <head> <title>Instagram</title> <meta charset="utf-8"> <style type="text/css"> </style> </head> <body> <?php if(!isset($_POST['send'])){ ?> <div class="container"> <form action="register.php" method="post"> <input type="text" name="login" placeholder="Put ur login"> <input type="password" name="password" placeholder="Put ur password"> <input type="submit" name="send" value="Registration"> </form> <?php } if (isset($_POST['send']) && !empty($_POST['login']) && !empty($_POST['password'])){ $queryL = "SELECT id FROM reg WHERE login = '".$_POST['login']."'"; $resL = mysqli_query($db , $queryL) or die ("Server Error #1"); if(mysqli_num_rows($resL)>0){ echo "This login already used!"; } else{ $query = "INSERT INTO reg(login, password) VALUES ('".$_POST['login']."', SHA1('".$_POST['password']."'))"; } mysqli_query($db, $query) or die ("Server Error #2"); echo("Reg is success!"); } else{ echo "Reg is fail, try again!"; } mysqli_close($db); ?> </div> </body> </html>
PHP: <?php $db = mysqli_connect("localhost" , "root" , "" , "reg") or die ("DataBase Erorr"); ?> <!DOCTYPE html> <html lang="ru"> <head> <title>Instagram</title> <meta charset="utf-8"> <style type="text/css"> </style> </head> <body> <?php if(!isset($_POST['send'])){ ?> <div class="container"> <form action="register.php" method="post"> <input type="text" name="login" placeholder="Put ur login"> <input type="password" name="password" placeholder="Put ur password"> <input type="submit" name="send" value="Registration"> </form> <?php } if (isset($_POST['send']) && !empty($_POST['login']) && !empty($_POST['password'])){ $queryL = "SELECT id FROM reg WHERE login = '".$_POST['login']."'"; $resL = mysqli_query($db , $queryL) or die ("Server Error #1"); if(mysqli_num_rows($resL)>0){ echo "This login already used!"; }else { $query = "INSERT INTO reg(login, password) VALUES ('".$_POST['login']."', SHA1('".$_POST['password']."'))"; mysqli_query($db, $query) or die ("Server Error #2"); echo("Reg is success!"); } }else{ echo "Reg is fail, try again!"; } mysqli_close($db); ?> </div> </body> </html>