473,383 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

register - using PHP & MySQL

George Lft
ok, first of all, i built my register page using dreamweaver tool which the codes haven been out of control. Now i'm thinking that turning over everything - by using this another set of codes. And these new sets of codes have overwhelmed me a bit. Here's the new code:
Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE TABLE `users` ( 
  3.   `ID` int(11) NOT NULL auto_increment, 
  4.   `Username` varchar(255) NOT NULL, 
  5.   `Password` varchar(255) NOT NULL, 
  6.   `Temp_pass` varchar(55) default NULL, 
  7.   `Temp_pass_active` tinyint(1) NOT NULL default '0', 
  8.   `Email` varchar(255) NOT NULL, 
  9.   `Active` int(11) NOT NULL default '0', 
  10.   `Level_access` int(11) NOT NULL default '2', 
  11.   `Random_key` varchar(32) default NULL, 
  12.   PRIMARY KEY (`ID`), 
  13.   UNIQUE KEY `Username` (`Username`), 
  14.   UNIQUE KEY `Email` (`Email`) 
  15. )ENGINE=MyISAM;
[php]
<?php require_once('db.php');
include('functions.php');

if(isset($_POST['register']))
{
if($_POST['username']!='' && $_POST['password']!='' &&
$_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' &&
valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE
&& checkUnique('Email', $_POST['email'])==TRUE)
{
$query = mysql_query("INSERT INTO users (`Username` , `Password`, `Email`, `Random_key`) VALUES
('".mysql_real_escape_string($_POST['username'])."',
'".mysql_real_escape_string(md5($_POST['password']))."',
'".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error());


$getUser = mysql_query("SELECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error());

if(mysql_num_rows($getUser)==1) {//there's only one MATRIX P

$row = mysql_fetch_assoc($getUser);
$headers = 'From: webmaster@ourdomainhere.com' . "\r\n" . 'Reply-To: webmaster@ourdomainhere.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion(); $subject = "Activation email from ourdomainhere.com";
$message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: http://www.ourdomainhere.com/confirm.php?ID=".$row['ID']."&amp;key=".$ row['Random_key']." Thank you for joining";

if(mail($row['Email'], $subject, $message, $headers)) {//we show the good guy only in one case and the bad one for the rest.

$msg = 'Account created. Please login to the email you provided during registration and confirm your membership.';
} else {
$error = 'I created the account but failed sending the validation email out. Please inform my boss about this cancer of mine'; }
}
else {
$error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.'; }
}
else {
$error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match'; }
}
?>



<?php if(isset($error)){ echo $error;}?>
<?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br />
Password: <input type="password" id="password" name="password" size="32" value="" /><br />
Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br />
Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br /> <input type="submit" name="register" value="register" /><br /> </form>
<?}?>

[/php]
this has been confusing to me, I don't know how the sequence should be . First , I create this register.php. Then , i run it at register.php without creating another messsageProcess.php . Then it checks IF all fields are entered. The two passwords match each other.The username is not taken. The email address is valid and also uique as well.


There's another confirmation page to be built . but i can't get through this one. I'm confused by how should this codes work. Please note before this i had my legs up on my desk, and built it using this: easy
[php]

<?php require_once('Connections/newland_tours.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="registration_failed.php";
$loginUsername = $_POST['username'];
$LoginRS__query = sprintf("SELECT username FROM tbl_users WHERE username=%s", GetSQLValueString($loginUsername, "text"));
mysql_select_db($database_newland_tours, $newland_tours);
$LoginRS=mysql_query($LoginRS__query, $newland_tours) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);

//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "frm_register")) {
$insertSQL = sprintf("INSERT INTO tbl_users (firstName, lastName, username, pwd, userGroup, address1, city, state_province, zip_postal, country) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['firstName'], "text"),
GetSQLValueString($_POST['lastName'], "text"),
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['pwd'], "text"),
GetSQLValueString($_POST['userGroup'], "text"),
GetSQLValueString($_POST['address1'], "text"),
GetSQLValueString($_POST['city'], "text"),
GetSQLValueString($_POST['state_province'], "text"),
GetSQLValueString($_POST['zip_postal'], "text"),
GetSQLValueString($_POST['country'], "text"));

mysql_select_db($database_newland_tours, $newland_tours);
$Result1 = mysql_query($insertSQL, $newland_tours) or die(mysql_error());

$insertGoTo = "login.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_newland_tours, $newland_tours);
$query_conn_newland = "SELECT * FROM tbl_users";
$conn_newland = mysql_query($query_conn_newland, $newland_tours) or die(mysql_error());
$row_conn_newland = mysql_fetch_assoc($conn_newland);
$totalRows_conn_newland = mysql_num_rows($conn_newland);
?>

[/php]

The whole image i'm trying to create is , a register page that checks username. email = email2 , a random key to confirm by user clicking on a link before she can start using her new username and password. The second msg is sent to her wishing you congratulations ,successful login page. The problems with NO.1 codes is it don't check for username and re-enter password or anything - no validation .it's just plain , with no function embedded in the form text fields. I suppose i have to connect it to the db handcoding, but i only understand that using the second code. I'm trying to use it in the first one but stuck in the beginning
[php]
<?php require_once('db.php');[/php] . Where in the second code ,the old one - it's something like this
[php]
<?php require_once('Connections/newland_tours.php'); ?>.
[/php]
aren't both the codes 1 and 2 are supposed to include :
[php]
<?php
// Set up connection to MySQL
$host = "localhost";
$user = "root";
$pwd = "";
$dbConn = mysql_connect($host,$user,$pwd);
// Connect to newland_tours database
$database = "newland_tours";
mysql_select_db($database);
$query_rs_countries = "SELECT countryID, countryName FROM tbl_country ORDER BY countryName ASC";
$rs_countries = mysql_query($query_rs_countries);
$row_rs_countries = mysql_fetch_assoc($rs_countries);
?> [/php]

the irony is the code 2 is working smoothly, the code 1 not at all. The reasons i drop off code 2 is that it's insecured when storing password,not encrypted, - the hidden fields are written out in the code where access level can be hacked. as well as confirmation not made where i can get up getting 1000 new users in one day.


Pls send some light here

Thanks, happy working !
Jan 5 '08 #1
1 4326
ronverdonk
4,258 Expert 4TB
It seems that no one read your thread or had any experience with this (I certainly have not). We are sorry we could not help you.

Maybe next time.

moderator
Feb 15 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: James | last post by:
HI, I'm looking for a script that will allow users/admins to have a one click backup solution for a MYSQL Database.. 'BACK DATABASE' button, click and its done... The a restore option, that...
7
by: AF | last post by:
I am a real novice to php and MySQL, with about a week's worth of reading and self tutoring. I have an urgent need to publish a database of information and need some guidance on how to do this. ...
0
by: Jamie Krasnoo | last post by:
Will placing Apache::RequestRec & Apache::RequestIO & APR::Table in startup.pl to load them up for multiple handlers have any bad side effects? I noticed that when I load them via startup.pl the...
8
by: iteamhub | last post by:
Hi Guest, i am a programmer and i have created a forum , where all can post your questions and discuss on various technical problems . More over you can learn a lot . The site link is...
2
by: DanWeaver | last post by:
I am trying to use a MySQL db hosted on a shared server as an ASP.NET Membership Provider and .net framework 3.5 (visual studio 2008) I am new to a lot of this and have found the following websites...
0
by: jipksa | last post by:
http://www.youtube.com/watch/v/as_b6...&feature=email Lecturer: Bro Sheikh Feiz 4rm Austrailia For how long, for how long are we going to be heedless of the signs of Allah (SWT), for how long...
0
by: youngwe | last post by:
Professionals please to help. I have got problem. This; Data of the dynamic text, go to the php. Php is a data register mysql. But; data register double. This problem spring flash. Php to php data...
6
by: viki1967 | last post by:
Not register double record in the DB MySQL I have developed a simple procedure asp to upload files csv and record data in the table mysql database. This procedure not register double record...
3
by: jonathan184 | last post by:
The code seems to be working fine for some records but I am thinking it is finding some other records with special characters and so on. I am looking for a way to insert the xml string with escaping...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.