Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP] Register Script with md5

Elite Diviner
Joined
Jan 26, 2006
Messages
483
Reaction score
5
Hey,

Im working today on a PHP register script for a MySQL database.
Iv learned HTML and a bit of Javascript.
Now because im new to PHP I dont want to make it too hard for myself.
I want to make a simple register script with 3 Rows: Login,Password and Email.

The thing is I do not know how to connect to mysql and the database(table)
I can write queries for SQL but I dont know how to make the password MD5 and it has to be MD5 its my goal :)

So my question is can anyone give me a link or maybe a example of a script I can use
Because I know a bit of Javascript I can read it already just not write it yet

Thanks for your support

-Darkco
 
Custom Title Activated
Loyal Member
Joined
Dec 10, 2007
Messages
2,194
Reaction score
263
Connect to MySQL databse.
PHP:
<?php
$host = "localhost";
$user = "root";
$pass = "YOUR_PASSWORD";
$db = "YOUR_DB";

$connect = mysql_connect("$host", "$user", "$pass");
mysql_select_db($connect,$db);
?>

md5 (for registration)
PHP:
$password = md5($_POST['password']);
 
Elite Diviner
Joined
Jan 26, 2006
Messages
483
Reaction score
5
Thanks for your help I made some progress with my script. See here my current script


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sv" lang="sv">
<head>
	<title>My Register Script</title>
</head>

<?PHP
include("config.php");

<body>

<div id="adminbody">
    <h2>Register </h2>
	<ul>
<TD colSpan=2 align=right> <div align="center" class="bigf Estilo5">
<?php

<form>
Login:
<input type="text" name="Login" />
<br />
Password:
<input type="text" name="Password" />
Delete Password:
<input type="text" name="deletepassword" />
Email:
<input type="text" name="Email" />
</form> 
</html>

<div align="center"><input class="button" type="submit" value="Done" onClick="$query" /></div>

$login = stripslashes($_POST['Login']);
$password = md5($_POST['password']);
$deletepassword = md5($_POST['deletepassword']);
$login = stripslashes($_POST['Email']);  


$query = "insert into tbl_test VALUES ('$login','$password','$deletepassword','0','10/7/2006','0','10/7/2006','0','A')";


</div>
</body>
?>

Now the onclick function isnt working yet what did I wrote wrong here. Remember its my PHP registe script so I would like to learn of my mistakes.

PS: THe config file looks like Rasta posted but then with the correct mySQL information ofc
 
Status: Pooping
Joined
Jul 16, 2008
Messages
861
Reaction score
25
There are plenty of register scripts. The best way is looking to other Register scripts and learn what is in there what you don't have.
 
Joined
Sep 10, 2006
Messages
2,817
Reaction score
1,417
Thanks for your help I made some progress with my script. See here my current script


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sv" lang="sv">
<head>
    <title>My Register Script</title>
</head>

<?PHP
include("config.php");

<body>

<div id="adminbody">
    <h2>Register </h2>
    <ul>
<TD colSpan=2 align=right> <div align="center" class="bigf Estilo5">
<?php

<form>
Login:
<input type="text" name="Login" />
<br />
Password:
<input type="text" name="Password" />
Delete Password:
<input type="text" name="deletepassword" />
Email:
<input type="text" name="Email" />
</form> 
</html>

<div align="center"><input class="button" type="submit" value="Done" onClick="$query" /></div>

$login = stripslashes($_POST['Login']);
$password = md5($_POST['password']);
$deletepassword = md5($_POST['deletepassword']);
$login = stripslashes($_POST['Email']);  


$query = "insert into tbl_test VALUES ('$login','$password','$deletepassword','0','10/7/2006','0','10/7/2006','0','A')";


</div>
</body>
?>
Now the onclick function isnt working yet what did I wrote wrong here. Remember its my PHP registe script so I would like to learn of my mistakes.

PS: THe config file looks like Rasta posted but then with the correct mySQL information ofc
You have absolutely no idea what you are doing, do you, either read at least very basic W3 php tutorials or give up. Honestly..
 
Last edited:
Master Summoner
Joined
Oct 9, 2008
Messages
572
Reaction score
14
Code:
<form>
Login:
<input type="text" name="Login" />
<br />
Password:
<input type="text" name="Password" />
Delete Password:
<input type="text" name="deletepassword" />
Email:
<input type="text" name="Email" />
</form>
should be:

Code:
<form action="" method="POST">
Login:
<input type="text" name="Login" />
<br />
Password:
<input type="text" name="Password" />
Delete Password:
<input type="text" name="deletepassword" />
Email:
<input type="text" name="Email" />
<input type="submit" value="register" />
</form>
the "<input type="submit"..." is a button, and also remember to declare action and method in "<form>"
 
Joined
Jun 8, 2007
Messages
1,985
Reaction score
490
There's still a bunch of things missing from that form.. What in the hell is the "Delete Password" field about? How/Why would you delete a password when registering? Did you mean "Repeat" Password? And another thing: Those password fields are text type. Nobody in their right mind would fill out that form!

Look, I'm going to walk you (and anyone else who cares) on how to make a form. Not just a technically functional form, but one that won't burn anyone's eyes when they look at it.

First, decide a name for your form. Let's say "myForm"
Second, you start with a Fieldset.

What is that? Well you'll find out, just do it.

You can make a fieldset like this:
Code:
<fieldset name="myForm_fieldset" id="myForm_fieldset">
</fieldset>
Also, a fieldset can have what we call a legend. That's for the title of your form in detail. Normally we do that bold or something to be fancy. (not too fancy)
Code:
<fieldset name="myForm_fieldset" id="myForm_fieldset">
  <legend><strong>My Form</strong></legend>
</fieldset>
Easy.

Now we add the form tags:
Code:
<fieldset name="myForm_fieldset" id="myForm_fieldset">
  <legend><strong>My Form</strong></legend>
  <form name="myForm" id="myForm" action="" method="post">
  </form>
</fieldset>
Okay next I'll tell you about labels. Labels are awesome because they make it easy to give each field a tab-index, a key response, and in most browsers the user can click the text, and the input box will become focused.
For this example, we're just going to use tabindex. Another important note with labels is the for attribute. Everytime you use a label, set for="input_name". In this case, for="username".

Let's make a username field.
Code:
<fieldset name="myForm_fieldset" id="myForm_fieldset">
  <legend><strong>My Form</strong></legend>
  <form name="myForm" id="myForm" action="" method="post">

  <label for="username" tabindex="1">
    Username 
    <input type="text" name="username" id="username" value="" />
  </label>

  </form>
</fieldset>
So that's easy enough. Now let's make the rest of the form. Don't forget to sepperate form fields with line breaks [<br />]

Code:
<fieldset name="myForm_fieldset" id="myForm_fieldset">
   <legend><strong>My Form</strong></legend>
   <form name="myForm" id="myForm" action="" method="post">

  <label for="username" tabindex="1">
    Username 
    <input type="text" name="username" id="username" value="" />
  </label>
<br />

  <label for="password" tabindex="2">
     Password
     <input type="password" name="password" id="password" value="" />
   </label>
<br />

  <label for="repeat_pass" tabindex="3">
     Repeat Password
     <input type="password" name="repeat_pass" id="repeat_pass" value="" />
   </label>
<br />

  <label for="email" tabindex="4">
     Email
     <input type="text" name="email" id="email" value="" />
   </label>
<br />

     <input type="submit" name="submit" id="submit" value="Submit" />
  </form>
</fieldset>
Example of the form .


Now for the register script, Click here:
http://forum.ragezone.com/f86/php-sql-user-database-in-under-5-min-tut-449083/
 
Last edited:
Elite Diviner
Joined
Jan 26, 2006
Messages
483
Reaction score
5
Thank you guys for the help !
Iv looked on the internet for some tutorials (which didnt help as much as your information)
But I finally got it working

After reading the topic of s-p-n I realized that I was actually trying to write HTML with PHP what dont work ofc. So I modified s-p-n's script and now it works with my database.

Now I got one more question. My script doesnt check if the username already exist it just put it twice in it. Any ideas ?
 
Last edited:
Newbie Spellweaver
Joined
Feb 10, 2008
Messages
30
Reaction score
0
Sorry if i screw this up, I haven't coded in a while but:

PHP:
<?
/Check if username is taken
                $checkuser = mysql_query("SELECT `login` FROM `tbl_test` WHERE `login` = '$login'"); 
                    $username_exist = mysql_num_rows($checkuser);
                        if($username_exist > 0)
                            {
                                echo "Username is already taken";
                                exit();
                            }
						else
							{
								//insert into datbase
							}
?>
 
Last edited:
Custom Title Activated
Loyal Member
Joined
Dec 21, 2007
Messages
1,040
Reaction score
127
or you could do it by functions ;3

PHP:
function checkUser($user) {
$userQuery = mysql_query("SELECT * FROM 'tbl_test' WHERE username = '$user'");
$userRows = mysql_num_rows($userQuery);
return $userRows;
}

$checkUser = checkUser($user);
if($checkUser >= 1) {
print "The username <b>".$user."</b> is already taken.";
} else {
// insert data into database
}
 
Last edited:
Elite Diviner
Joined
Jan 26, 2006
Messages
483
Reaction score
5
Thanks this was exactly what I need it worked like a charm.
I'm starting to learn php and it isnt so hard as it looks.
ofc I have much to learn and I wonder if I someday can write these codes and not copy and modify them but ill see.

PS:
Code:
VALUES("'.$user.'", "'.$pass.'")';
why does my query have those weird weird dots because if I delete them (like you should write a query for MSSQL) it will bug me
 
Back
Top