Jump to content

New to php, need help to add a registration field in code.


Albana_12

Recommended Posts

Hi everyone,

 

I wanted to let you know first that i am real new into this. I am trying to build a user management system and i can't seem to add a registration field.

 

I got the free script uM Script and here's the code, please help me on this one:

 

REGISTER.PHP

<!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="en-GB">
<head>
<title>Member Registration</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="robots" content="index, follow" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />

<script type="text/javascript" src="js/jquery-1.6.2.js"></script>
<script type="text/javascript" src="js/script.js"></script>

<script type="text/javascript">
	$(document).ready(function(){

		$('#regForm').submit(function(e) {
			register();
			e.preventDefault();	
		});	
	});
</script>

</head>
<body>
<table align="center" width="100%" cellspacing="1" cellpadding="1" border="0">
	<tr>
		<td align="left"><a href="index.php">Home</a> | <a href="login.php">Log in</a> | <a href="register.php">Register</a> | <a href="pass_reset.php">Reset Password</a> | <a href="contact_us.php">Contact Us</a></td><td align="right"><a href="admin/login.php">Admin Login</a></td>
	</tr>
</table>
<hr/>
<p>Register</p>
<p>Use the form below to register.</p>
<hr/>
<div class="done"><p>Registration successful! <a href="login.php">Click here</a> to login.</p></div><!--close done-->
<div class="form">
<form id="regForm" action="reg_submit.php" method="post">
	<table align="center" width="50%" cellspacing="1" cellpadding="1" border="0">
	  <tr>
		<td colspan="2" ></td>
	  </tr>
	  <tr>
		<td>
			<label for="username">Username:</label>
		</td>
		<td>
		<input onclick="this.value='';" name="username" type="text" size="25" maxlength="8" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>"/>
		</td>
	  </tr>
	  <tr>
		<td>
			<label for="password">Password:</label>
		</td>
		<td>
		<input name="password" type="password" size="25" maxlength="15" />
		</td>
	  </tr>
	  <tr>
		<td>
			<label for="email">Email:</label>
		</td>
		<td>
		<input onclick="this.value='';" name="email" type="text" size="25" maxlength="50" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>"/>
		</td>
	  </tr>
         <tr>
		<td><label for="phone"><label>Phone:</label></td><td><input type="text" name="phone" value="<?php if(isset($_POST['phone'])){echo $_POST['phone'];}?>"/></td>
	</tr>
		<td> </td>
		<td>
			<input type="submit" name="register" value="Register" /><img id="loading" src="images/loading.gif" alt="working.." />
		</td>
	  </tr>
	  <tr>
		<td colspan="2"><div id="error"> </div></td>
	  </tr>
	</table>
</form>
</div><!--close form-->
</body>
</html>

 

REG.SUBMIT.PHP

 

<?php
require_once('lib/connections/db.php');
include('lib/functions/functions.php');
$sitesettings = getSiteSettings();
$site_url = $sitesettings[0]['site_url'];

//For registration

// we check if everything is filled in and perform checks

if(!$_POST['username'])
{
	die(msg(0,"<p>Please enter a username.</p>"));
}

if(strlen($_POST['username'])<3 || strlen($_POST['username'])>15)
{
	die(msg(0,"<p>Username must be between 3 and 15 characters.</p>"));
}

elseif(uniqueUser($_POST['username']))
{
	die(msg(0,"Username already taken."));
}


elseif(!$_POST['password'])
{
	die(msg(0,"<p>Please enter a password.</p>"));
}

elseif(strlen($_POST['password'])<5)
{
	die(msg(0,"<p>Usernames must be atleast 5 characters.</p>"));
}

elseif(!$_POST['email'])
{
	die(msg(0,"<p>Please enter an email address.</p>"));
}

/*elseif(validateEmail($_POST['email']))
{
	die(msg(0,"<p>Invalid email address.</p>"));
}*/

elseif(uniqueEmail($_POST['email']))
{
	die(msg(0,"<p>Email taken. Please select another email address.</p>"));
}
elseif(!$_POST['phone'])
	{
		die(msg(0,"Phone numbers must be of numeric type only."));
	}
else
	{
		$res = addUser($_POST['username'],$_POST['password'],$_POST['email'], $_POST['phone'],$site_url);
			if ($res == 1){
				die(msg(0,"Failed to send activation email. Please contact the site admin."));
			}
			if ($res == 2){
				die(msg(0,"There was an error registering your details. Please contact the site admin."));
			}
			if ($res == 99){
				die(msg(1,"<p>Registration successful! <a href='login.php'>Click here</a> to login.</p>"));
			}
	}

function msg($status,$txt)
{
	return '{"status":'.$status.',"txt":"'.$txt.'"}';
}

?>

 

And the code of the function:

 

//----------Function for adding user's profile----------
function addUser($user,$pass,$email,$site_url)
{
	$user = secureInput($user);
	$pass = secureInput($pass);
   $email = secureInput($email);
$site_url = secureInput($site_url);
  		
	//Encrypt password for database
		$salt = 's+(_a*';
		$pass = md5($pass.$salt);

		$reg_date = date("l, M j, Y, g:i a");

		$sql = "INSERT INTO users (username,password,email,active,level_access,reg_date) VALUES ('".$user."','".$pass."','".$email."',0,2,'".$reg_date."')"; 
		$res = mysql_query($sql);
		if($res){
			//build email to be sent
			$to = $email;
			$subject = $site_url;
			$subject .= ": Activate Your Account";

			$message = "
				<html>
				  <head>
					<title>Account Activation</title>
				  </head>
				  <body>
					<h3>Account Activation</h3>
					<p>Dear ".$user.", thank you for registering at ".$site_url.".</p>
					<p>Please click on the link below to activate your account:</p>
					<a href='".$site_url."/confirm_user_reg.php?prsn=".$user."'>http://www.".$site_url."</a>.
					<p>If the above link does not work, copy and paste the below URL to your browser's address bar:</p>
					<p><i>http://www.".$site_url."/confirm_user_reg.php?prsn=".$user."</i></p><br/>
					<p>If you did not initiate this request, simply disregard this email, and we're sorry for bothering you.</p>
					<br/><br/>
					<p>Sincerely,</p>
					<p>The ".$site_url." Team.</p>
				  </body>
				</html>
				";

			// To send HTML mail, the Content-type header must be set
			$headers = "MIME-Version: 1.0\r\n";
			$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

			if($mail_send = mail($email, $subject, $message, $headers)) {
			} return 99;
			 return 1;
		} 
		else return 2;	

}

 

I know i'm wrong somewhere because when i register a user the phone number won't post on the "phone" field on database.

Link to comment
Share on other sites

While I see you added the phone number to the evaluation and to

$res = addUser($_POST['username'],$_POST['password'],$_POST['email'], $_POST['phone'],'test_3.php');

 

You have not added it to the function

function addUser($user,$pass,$email,$site_url)

Nor to the insert

$sql = "INSERT INTO users (username,password,email,active,level_access,reg_date) VALUES ('".$user."','".$pass."','".$email."',0,2,'".$reg_date."')";

 

Have you added a column to the database for the phone number?

Link to comment
Share on other sites

Hey Sunfighter,

 

Thank you very much for your answer...

 

I added the code as you told me, now it won't display any error, but when i try to add a new user the information which goes to the database on the phone field... it just goes a number "0" i mean, not the phone numnber, just 0.

Link to comment
Share on other sites

This would be my database structure...

 

CREATE TABLE IF NOT EXISTS `users` (
  `id` int( NOT NULL AUTO_INCREMENT,
  `username` varchar( NOT NULL,
  `password` varchar(32) NOT NULL,
  `temp_pass` varchar(32) NOT NULL,
  `temp_pass_active` int(1) NOT NULL,
  `first_name` varchar(25) NOT NULL,
  `last_name` varchar(25) NOT NULL,
  `email` varchar(35) NOT NULL,
  `dialing_code` int(5) NOT NULL,
  `phone` int(25) NOT NULL,
  `city` varchar(80) NOT NULL,
  `country` varchar(80) NOT NULL,
  `thumb_path` varchar(150) NOT NULL,
  `img_path` varchar(150) NOT NULL,
  `active` int(1) NOT NULL,
  `level_access` int(1) NOT NULL,
  `reg_date` varchar(45) NOT NULL,
  `last_active` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.