Simple PHP Registration Code
Making your own script is not too hard, you'll just need to make sure that your script is Safe for SQL Injections and more.
On this blog post, i will show you how to make a simple registration script on your Rohan Private Server.
First you need xampp/wampp or IIS.
Make sure that your xampp/wamp or IIS has SQLSRV function.
On xampp, go to your htdocs folder and create new folder name it as "Register"
Inside your "Register" folder create 3 .txt document and name it with the following.
index.php
register.php
dbconn.php
Use text editor like notepad,notepad++ or sublime to edit your .php files.
First we need to edit our dbconn.php
and type this following.
on $serverName = ""; you need to add your Server Name on your SQL Server Management Studio.
<?php
$serverName = "";
$uid = "";
$pwd = "";
$connectioninfo = array("UID" => $uid,
"PWD" => $pwd,
"Database" => "RohanUser"
);
$conn = sqlsrv_connect($serverName, $connectioninfo);
if($conn === false)
{
die (-1000);
}
?>
In my case.
$serverName = "CHOW-ZENON\SQLEXPRESS";
$uid = "sa";
$pwd = "Password101!";
Now we're going to make a simple form. Check the video below.
Here's the code
<html>
<head>
<title> Simple Registration </title>
</head>
<body>
<form method="POST" action="register.phh">
<input type="text" name="username" placeholder="Please enter your Username"><br>
<input type="password" name="password" placeholder="Please enter your Password"><br>
<input type="Submit" Value="Submit">
</form>
</body>
</html>
On your register.php, check the video below.
Here's the code.
<?php
include 'dbconn.php';
$connectioninfo = array("UID" => $uid,
"PWD" => $pwd,
"Database" => "RohanUser"
);
$conn = sqlsrv_connect($serverName, $connectioninfo);
$id = $_POST['username'];
$pw = $_POST['password'];
$pw2 = md5($pw);
$sql = "INSERT INTO [RohanUser].[dbo].[TUser]
([login_id]
,[login_pw]
,[grade])
VALUES
(?
,?
,?)
";
$params = array("$id","$pw2",250);
$stql = sqlsrv_query($conn,$sql,$params);
if($stql === false){
echo "Registration Failed";
}else
{
echo "Registration Success!";
}
?>
Simple PHP Registration Code
Reviewed by Unknown
on
4:06 PM
Rating:
No comments: