Home >>MySQL Tutorial >PHP MySQL Secure Registration Page
<?php //First create a database test $con=mysqli_connect("localhost","root","","test") or die(mysqli_error()); //create table stuinfo inside test database $que="CREATE TABLE userinfo ( user_id INT AUTO_INCREMENT PRIMARY KEY , user_name VARCHAR( 50 ) NOT NULL , password VARCHAR( 50 ) NOT NULL , mobile BIGINT NOT NULL , gender ENUM( 'm', 'f' ) NOT NULL , )"; mysqli_query($con,$que); ?>
<?php if(isset($_POST['reg'])) { if($_POST['un']=="" || $_POST['pwd']=="" $_POST['mob']=="") { $err="fill your user name first"; } else { $r=mysqli_query($con,"SELECT * FROM userinfo where user_name='{$_POST['un']}'"); $t=mysqli_num_rows($r); if($t) { $err="user already exists choose another"; } else { mysqli_query($con,"INSERT INTO userinfo values('','{$_POST['un']}','{$_POST['pwd']}','{$_POST['mob']}','{$_POST['gen']}')"); header('location:https://www.phptpoint.com'); } } } ?>
<form method="post" enctype="multipart/form-data"> <table width="438" border="5" align="center"> <font color="#FF0000"><?php echo $err; ?></font> <tr> <td width="204" height="47">Enter Your User Name </td> <td width="218"><input type="text" name="un"/></td> </tr> <tr> <td height="39">Enter Your Password </td> <td><input type="password" name="pwd"/></td> </tr> <tr> <td height="47">Enter Your Mobile </td> <td><input type="text" name="mob"/></td> </tr> <tr> <td height="33">Select Your Gender </td> <td> Male<input type="radio" name="gen" value="m"/> Female<input type="radio" name="gen" value="f"/> </td> </tr> <tr> <td align="center" colspan="2"> <input type="submit" name="reg" value="Register"/> <input type="reset" value="Reset"/> </td> </tr> </table> </form>