Username:
Password:
Remember me:
Register

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)


Search forums via Google


0 Users appreciate this thread.

Creating a register in PHP
Started by ryanb000977
(2013-06-28 01:18:17)
ryanb000977 (2013-06-28 01:18:17)
Hello, today I will show you the code and some explanation to creating a register script! This is the one used in my site, ChatPlaza Extended.

1. Start by creating the table in the database
Setup your table like the following:
Column One
Name: id
Type: int
Length: 5
Other: AUTO INCREMENT
Column Two
Name: username
Type: char
Length: 20
Other: None
Column Three
Name: password
Type: text
Length: Leave Blank
Other: None
Column Four
Name: ip
Type: char
Length: 15
Other None

Feel free to add other column's as well

2. Use the code below
Source Code
<?php session_start(); $logged = $_SESSION['username']; mysql_connect("localhost","USER","PASS" ); mysql_select_db("DATABASE" ); $user3 = $_POST['user']; $user2 = mysql_real_escape_string($user3); $user = htmlspecialchars($user2, ENT_QUOTES); $pass4 = $_POST['pass']; $pass3 = mysql_real_escape_string($pass4); $pass2 = htmlspecialchars($pass3, ENT_QUOTES); $pass = hash('sha256', $pass2); $select = mysql_query("SELECT * FROM user_table WHERE username='$user' and password='$pass'" ); $count = @mysql_num_rows($select); $ip = $_SERVER['REMOTE_ADDR']; if($user != '' && $pass != '' && $count == '0' { $insert = mysql_query("INSERT INTO user_table (username, message, ip) VALUES ('$user','$pass','$ip'" ); $msg = "<p>You have been registered!</p>"; } elseif($user != '' && $pass != '' && $count != '0' { $msg = "<p>There is already a user using that username!</p>"; } else { $msg = "<form method=\"post\" action=\"register.php\"> <table> <tr> <td>Username:</td> <td><input name=\"user\" type=\"text\" value=\"\" maxlength=\"20\" /></td> </tr> <tr> <td>Password:</td> <td><input name=\"pass\" type=\"password\" value=\"\" /></td> </tr> <tr> <td></td> <td><input type=\"submit\" value=\"Register\" /></td> </tr> </table> </form>"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Register</title> <style type="text/css"> body { background-color: yellow; } h1 { color: red; } </style> </head> <body> <center> <h1>Register</h1> <?php echo $msg; ?> </center> </body> </html> <?php mysql_close(); ?>


Be sure to edit the MySQL stuff and make the file named register.php

Click Here, for another version of the code

The next code I will do will be a login!

/

This post has been edited one or more times, the last time was:
2013-07-15 17:26:48

ryanb000977 (2013-06-28 01:18:38)

ryanb000977 (2013-06-28 01:37:40)
Duh, it's web programing
(Capt.)Orb (2013-06-28 12:08:46)
Not bad, not bad at all.

I would recommend tracking ip's as well.


For the N00bies at coding who just copy and paste, replace the smiley with a ) .
Aviation fact: The a380 is the largest commerical aircraft in service!

Go to Splashiverse! Splashiverse
klubadmin (2013-06-28 20:27:52)
I'd recommend using PDO instead. Set a better example for the n00bs to follow.
socialcu.be
3dsklub.cf

Like what I said? +respect
>Official Trinate Spriter<
SomeLuigi (2013-06-28 22:57:06)
I'd use MySQLi, because I prefer it to PDO. MySQL_xxxx functions are deprecated and will be removed, so you should use MySQLi or PDO.

Personally, I use MySQLi with my own compatibility layer.
SomeLuigi is changing in 2015.
klubadmin (2013-07-02 02:55:53)
Either one is better.
socialcu.be
3dsklub.cf

Like what I said? +respect
>Official Trinate Spriter<
SPCOxion (2013-07-03 21:51:02)
Nice.

Wow. I managed to get a ) out of nowhere.

This post has been edited one or more times, the last time was:
2013-07-04 08:35:11

SPCOxion (2013-07-04 01:45:00)
Errors show
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user'@'localhost' (using password: YES) in /home/spectres/public_html/register.php on line 7

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'spectres'@'localhost' (using password: NO) in /home/spectres/public_html/register.php on line 9

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/spectres/public_html/register.php on line 9

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'spectres'@'localhost' (using password: NO) in /home/spectres/public_html/register.php on line 13

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/spectres/public_html/register.php on line 13

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'spectres'@'localhost' (using password: NO) in /home/spectres/public_html/register.php on line 19

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/spectres/public_html/register.php on line 19

Warning: mysql_query() [function.mysql-query]: Access denied for user 'spectres'@'localhost' (using password: NO) in /home/spectres/public_html/register.php on line 25

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/spectres/public_html/register.php on line 25


Code show
<?php

session_start();

$logged = $_SESSION['username'];

mysql_connect("localhost","user","pass";

mysql_select_db("Database";

$user3 = $_POST['user'];

$user2 = mysql_real_escape_string($user3);

$user = htmlspecialchars($user2, ENT_QUOTES);

$pass4 = $_POST['pass'];

$pass3 = mysql_real_escape_string($pass4);

$pass2 = htmlspecialchars($pass3, ENT_QUOTES);

$pass = hash('sha256',$pass2);

$select = mysql_query("SELECT * FROM user_table WHERE username='$user'";

$count = @mysql_num_rows($select);

if($user != '' && $pass != '' && $count == '0'{
$insert = mysql_query("INSERT INTO Table (username, password) VALUES ('$user','$pass'";
$msg = "<p>You have been registered!</p>";
}
elseif($user != '' && $pass != '' && $count != '0'{
$msg = '<p>Someone already has that username! <a href="register.php">Retry</a>';
}
else{
$msg = "<form method=\"post\" action=\"register.php\">
<table>
<tr>
<td><strong>Username</strong></td>
<td>:</td>
<td><input name=\"user\" type=\"text\" value=\"\" maxlength=\"20\" /></td>
</tr>
<tr>
<td><strong>Password</strong></td>
<td>:</td>
<td><input name=\"pass\" type=\"text\" value=\"\" /></td>
</tr>
<tr>
<td><strong>Submit</strong></td>
<td>:</td>
<td><input type=\"submit\" value=\"Register\" /></td>
</tr>
</table>
</form>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Register</title>
</head>
<body>
<center>
<h1>Register</h1>
<?php
echo $msg;
?>
</center>
</body>
</html>
<?php
mysql_close();
?>


Since I'm banned, I can't post new comments.

So I'll just edit this one.

What would I edit for my username/password/everything else? Also, I assume I would use my cPanel user and pass, right?

This post has been edited one or more times, the last time was:
2013-07-08 11:20:15

klubadmin (2013-07-07 02:27:24)
@SPCOxion Make sure you are using the username/password/url/database names specific to your host/website. It sounds like you couldn't connect.
socialcu.be
3dsklub.cf

Like what I said? +respect
>Official Trinate Spriter<
Fayne_Aldan (2013-10-15 09:08:42)
Uh.... Thx?
wellsandlava (2013-11-06 04:17:48)
Nice tutorial. " but it's recommended to use PDO Nowdays.

This post has been edited one or more times, the last time was:
2013-11-06 04:18:08

This account is under a new owner
DrakeJericho (2014-03-15 19:49:06)
I love you.
TheAlexRider (2014-04-16 23:47:55)
Lol drake.
 

Log in to submit a comment

This topic's ID: 48915

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)




Total registered users: 8321
New registered users today: 7
Newest registered user: ElegantVulpes

©  Copyright 2026 3DSPlaza. All Rights Reserved