Tech Support Guy banner
Status
Not open for further replies.
1 - 1 of 1 Posts

· Registered
Joined
·
774 Posts
Discussion Starter · #1 ·
Hi I have created a php script (with book help) its to create a member with user and pass. Its only for an excercise in college to be run on their server so no big stress for security etc.

This is the code

<?php
// Connects to your Database
mysql_connect("localhost", "xxxs", "xxxxxxxx") or die(mysql_error());
mysql_select_db("coll") or die(mysql_error());

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
die('You did not complete all of the required fields');
}

// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username '.$_POST['username'].' is already in use.');
}

// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. ');
}

$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}

// now we insert it into the database
$insert = "INSERT INTO users (username, password)
VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
$add_member = mysql_query($insert);
?>

Registered

Thank you, you have registered - you may now login</a>.

<?php
}
else
{
?>

" method="post">
Username:

Password:

Confirm Password:


<?php
}
?>

It works a treat but you have a white page where you can register but what I would really like is to have the register fields on a website I have created. Like this log in form is on this site >> http://www.llandarcy-asc.co.uk/ so what I think i need is some alteration oin the code so the register form uses the php code. I hope you know what I mean and any help would be great

Cheers

Gus
 
1 - 1 of 1 Posts
Status
Not open for further replies.
Top