...

View Full Version : User Registration Help with coding



52designs
03-11-2008, 01:31 AM
hey guys I have the following code I got out of a book for a user registration form. What I am needing to know is how am I suppose to connect to my MYSQL database. Can you guys tell me how to do this?

EDIT ***THE LINK TO THE PAGE IS http://www.52designs.net/php/register.php ****
Here is the code I have:



<?php
function in_use($userName) {
global $member

$query = "SELECT userName FROM $member WHERE userName = '$userName'";
$result = mysql_query($query) ;
if(!mysql_num_rows($result)) return 0;
else return 1;
}

function register_form() {
global $userName, $email, $firstName, $lastName;
global $PHP_SELF;
?>
<center><h3>Create Your Account!</h3></center>
<form method="POST" action="<?php echo $PHP_SELF ?>">
<input type="hidden" name="action" value="register">
<div align="center"><center><table border="1" width="90&#37;">
<tr>
<th width="30%" nowrap>Desired User Name</th>
<td width="70%"><input type="text" name="userName" value="<?php echo $userName ?>" size="8" maxlength="8"></td>
</tr>

<tr>
<th width="30%" nowrap>Desired Password</th>
<td width="70%"><input type="PASSWORD" name="password" value="<?php echo $password ?>" size="8" maxlength="8"></td>
</tr>

<tr>
<th width="30%" nowrap>Retype Password</th>
<td width="70%"><input type="PASSWORD" name="password2" size="15"></td>
</tr>

<tr>
<th width="30%" nowrap>First Name</th>
<td width="70%"><input type="text" name="FirstName" value="<?php echo $firstName ?>" size="20"></td>
</tr>

<tr>
<th width="30%" nowrap>Last Name</th>
<td width="70%"><input type="text" name="lastName" value="<?php echo $lastName ?>" size="20"></td>
</tr>

<tr>
<th width="30%" nowrap>E-Mail Address</th>
<td width="70%"><input type="text" name="emai;" value="<?php echo $email ?>" size="20"></td>
</tr>

<tr>
<th width="30%" colspan="2" nowrap>
<input type="submit" value="Submit">
<input type="reset" value="Reset"></th></tr></table></center></div></form>

<?php
}
function create_account() {
global $userName, $password, $password2, $firstName, $lastName, $email;
global $db234976774, $member;
if(empty($userName)) error_message("Enter your Desired User Name!");
if(empty($password)) error_message("Enter your desired password!");
if(strlen($password) < 4 ) error_message("Password too short!");
if(empty($password2)) error_message("Retype your password for verification!");
if(empty($firstName)) error_message("Enter your First Name!");
if(empty($lastName)) error_message("Enter your Last Name!");
if(empty($email)) error_message("Enter your E-Mail!");
if($password != $password2) error_message("Passwords Do not match, please verify them!");
$link_id = db_connect($db234976774);
if(in_use($userName)) error_message("$userName is in use. Please choose a different ID.");
$query = "INSERT INTO member VALUES ('$userName', password('$password'), '$username', '$email', '$firstName', '$lastName')";
$result = mysql_query($query);
if(!result) error_message(sql_error());
?>
<center><h3><?php echo $firstName $lastName ?>, thank you for registering with us!</h3></center>
<?php
html_footer();
}
switch($action) {
case "register":
create_account();
break;
default:
html_header();
register_form();
html_footer();
break;
}
?>

Fumigator
03-11-2008, 03:05 AM
Google "php +mysql +connect" or maybe "php +mysql +tutorial".

GO ILLINI
03-12-2008, 05:18 AM
http://www.tizag.com/mysqlTutorial/mysqlconnection.php
Tizag's tutorials are very good so ide bookmark it;)

-Adam



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum