473,581 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

register - using PHP & MySQL

George Lft
26 New Member
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
  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`) 
<?php require_once('d b.php');
include('functi ons.php');

if($_POST['username']!='' && $_POST['password']!='' &&
$_POST['password']==$_POST['password_confi rmed'] && $_POST['email']!='' &&
valid_email($_P OST['email'])==TRUE && checkUnique('Us ername', $_POST['username'])==TRUE
&& checkUnique('Em ail', $_POST['email'])==TRUE)
$query = mysql_query("IN SERT INTO users (`Username` , `Password`, `Email`, `Random_key`) VALUES
('".mysql_real_ escape_string($ _POST['username'])."',
'".mysql_real_e scape_string(md 5($_POST['password']))."',
'".mysql_real_e scape_string($_ POST['email'])."', '".random_strin g('alnum', 32)."')") or die(mysql_error ());

$getUser = mysql_query("SE LECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_e scape_string($_ POST['username'])."'") or die(mysql_error ());

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

$row = mysql_fetch_ass oc($getUser);
$headers = 'From: webmaster@ourdo mainhere.com' . "\r\n" . 'Reply-To: webmaster@ourdo mainhere.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion(); $subject = "Activation email from ourdomainhere.c om";
$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.ourdomainhe re.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="<?=$_SE RVER['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_co nfirmed" 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>

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 require_once('C onnections/newland_tours.p hp'); ?>
if (!function_exis ts("GetSQLValue String")) {
function GetSQLValueStri ng($theValue, $theType, $theDefinedValu e = "", $theNotDefinedV alue = "")
$theValue = get_magic_quote s_gpc() ? stripslashes($t heValue) : $theValue;

$theValue = function_exists ("mysql_real_es cape_string") ? mysql_real_esca pe_string($theV alue) : mysql_escape_st ring($theValue) ;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValu e) : "NULL";
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theV alue) . "'" : "NULL";
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
case "defined":
$theValue = ($theValue != "") ? $theDefinedValu e : $theNotDefinedV alue;
return $theValue;

// *** Redirect if username exists
$MM_flag="MM_in sert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedir ect="registrati on_failed.php";
$loginUsername = $_POST['username'];
$LoginRS__query = sprintf("SELECT username FROM tbl_users WHERE username=%s", GetSQLValueStri ng($loginUserna me, "text"));
mysql_select_db ($database_newl and_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($loginFoundU ser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($ MM_dupKeyRedire ct,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedir ect = $MM_dupKeyRedir ect . $MM_qsChar ."requsername=" .$loginUsername ;
header ("Location: $MM_dupKeyRedir ect");

$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)",
GetSQLValueStri ng($_POST['firstName'], "text"),
GetSQLValueStri ng($_POST['lastName'], "text"),
GetSQLValueStri ng($_POST['username'], "text"),
GetSQLValueStri ng($_POST['pwd'], "text"),
GetSQLValueStri ng($_POST['userGroup'], "text"),
GetSQLValueStri ng($_POST['address1'], "text"),
GetSQLValueStri ng($_POST['city'], "text"),
GetSQLValueStri ng($_POST['state_province '], "text"),
GetSQLValueStri ng($_POST['zip_postal'], "text"),
GetSQLValueStri ng($_POST['country'], "text"));

mysql_select_db ($database_newl and_tours, $newland_tours) ;
$Result1 = mysql_query($in sertSQL, $newland_tours) or die(mysql_error ());

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

mysql_select_db ($database_newl and_tours, $newland_tours) ;
$query_conn_new land = "SELECT * FROM tbl_users";
$conn_newland = mysql_query($qu ery_conn_newlan d, $newland_tours) or die(mysql_error ());
$row_conn_newla nd = mysql_fetch_ass oc($conn_newlan d);
$totalRows_conn _newland = mysql_num_rows( $conn_newland);


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 require_once('d b.php');[/php] . Where in the second code ,the old one - it's something like this
<?php require_once('C onnections/newland_tours.p hp'); ?>.
aren't both the codes 1 and 2 are supposed to include :
// 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_count ries = "SELECT countryID, countryName FROM tbl_country ORDER BY countryName ASC";
$rs_countries = mysql_query($qu ery_rs_countrie s);
$row_rs_countri es = mysql_fetch_ass oc($rs_countrie s);
?> [/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 4339
4,258 Recognized Expert Specialist
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.

Feb 15 '08 #2

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

Similar topics

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 shows all current backups, and restores the selected one with one click...
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. This question might be more suited to a MySQL newsgroup, but since php and MySQL seem to have become almost married to one another, and since...
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 handlers that use them don't complain that they don't have the use statements within the module code and still work as normal. Jamie Krasnoo --
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 http://forum.iteamhub.com/ The topics i am going to deal with are : 1. Php programming (A language through which you can build great websites). 2. Mysql...
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 which offer some degree of help but by no means a complete solution or uncomplicated explanation of whats involved: 1) ...
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 are we going to be busy with the Dunya (World), busy making money, chasing our dreams, following our desires? We know my brothers and sisters that...
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 normal register. Shortly data of double register mysql. Please help. ( My english because of excuse me all )
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 because I have one control existing records in the table mysql database. But if you reinsert the same file csv the rows first excluded are now...
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 a bunch of chars This is the message i got DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.