Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1923 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

user registration

Thread title: user registration
Closed Thread    
    Thread tools Search this thread Display Modes  
03-04-2007, 05:33 PM
#1
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old  user registration

ok so what this script is subpossed to do is set $error to 0, meaning there are no errors. The register script has fields which is, usernme passwrd, and email. the script will check for errors in the fields such as missing fields and if the passwords match, that all works fine. if there is a blank field it will set $error to 1, meaning there is errors. If there are no errors it will point to ?action=register.Add which will add the information to the database, but when i fill the stuff in it will just put in the database blank information. Ive tried everything.

I've simplified it down and once i get it working im going to add
PHP Code:
if($usernme == "" || $passwrd == "" || $email == "" || $passwrd2 == "") { header("location:register.php"); exit; } else { mysql_query("INSERT INTO users (username, password, email, admin, id) VALUES ('$usernme','$passwrd','$email','0','$id') } 
PHP Code:
<?php
include("config.php");

if ( 
$_SESSION['logid'] == "f8e3r6e24gh" ) {
echo 
"you need to  <a href='login.php?action=logout'>logout</a> before you can do this";
} else {

$id rand(100000999999);

if (
$_GET['action'] == "register")
    {            
    
$error "0";
    
$usernme trim($_POST['usernme']);
    
$password trim($_POST['passwrd']);
    
$password2 trim($_POST['passwrd2']);
    
$email trim($_POST['email']);
    
$id $_POST['id'];
    
    
$sql mysql_query("SELECT * FROM users WHERE username='$usernme'");
    
$result mysql_num_rows($sql); 
    if (
$result == "1") { $error "1"; echo "the username, $usernme, already exists<br />"; }
    if (
$usernme == "") { $error "1"; echo "please choose a username<br />"; }
    if (
$passwrd == "" || $passwrd2 == "") { $error "1"; echo "please fill in your password(s)<br />"; }
    if (
$passwrd == "$passwrd2") { } else { $error "1"; echo "your passwords do not match<br />"; }
    if (
$email == "") { $error "1"; echo "please fill in your email<br />"; }
    if (
$email == "&" || $email == ".") { } else { $error="1"; echo "invalid email address<br />"; }
    if (
$error == "1") { header("location:register.php"); } else { header("location:register.php?action=register.Add"); }
    }
    if (
$_GET['action'] == "register.Add")
        {
        
mysql_query("INSERT INTO users (username, password, email, admin, id) VALUES ('$usernme','$passwrd','$email','0', '$id')");
        }    
        
echo 
"<form action='register.php?action=register' method='post'>";
echo 
"<table cellspacing='5'>";
echo 
"<tr><td><b>user id :</b></td><td><center>$id</center></td></tr>";
echo 
"<tr><td><b>username :</b></td><td><input type='text' name='usernme' value='$usernme' size='30'></td></tr>";
echo 
"<tr><td><b>password :</b></td><td><input type='password' name='passwrd' size='30'></td></tr>";
echo 
"<tr><td><b>confirm pass :</b></td><td><input type='password' name='passwrd2' size='30'></td></tr>";
echo 
"<tr><td><b>email :</b></td><td><input type='text' name='email' value='$email' size='30'></td></tr>";
echo 
"<input type='hidden' name='id' value=$id>";
echo 
"<tr><td><center><a href='login.php'>Login</a></center></td><td><div align='right'><input type='submit' value='Register'></td></tr>";
echo 
"</table></form>"


?>

03-04-2007, 06:09 PM
#2
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

Okay few things I want to mention.

Instead of using trim() on your post values, use mysql_real_escape_string(). Also, instead of using '= ""' to see if values are empty, use if (!empty($value)), as it is much faster than comparing it to "". Also, instead of just echoing all the table, just put it outside PHP tags, and it will be outputted.

Also, since you are using the post method, you shouldn't be setting the action as ?action=register.Add or whatever, but instead just go to register.php in the action, and chcek if the submit button was set.

03-04-2007, 06:14 PM
#3
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old

how would i check if it was set

03-04-2007, 06:19 PM
#4
Immersion is offline Immersion
Status: Senior Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 918
iTrader: 5 / 100%
 

Immersion is on a distinguished road

  Old

if(isset($_POST['formname'])) {
blargh
} else {
it was not set
}

03-04-2007, 07:31 PM
#5
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old

i got it working, thanks. just had to make a little changes.

03-14-2007, 07:22 PM
#6
mikeroq is offline mikeroq
mikeroq's Avatar
Status: Member
Join date: Feb 2006
Location: Ponca City, OK
Expertise: xHTML/CSS/PHP/Computer Tech
Software: Photoshop, Notepad++, Winamp
 
Posts: 332
iTrader: 5 / 100%
 

mikeroq is an unknown quantity at this point

Send a message via AIM to mikeroq Send a message via MSN to mikeroq Send a message via Yahoo to mikeroq

  Old

Simple Checking for empty or set:
PHP Code:
<?php
if (!$apple)
{
echo 
"there is no apple";
}
else {
echo 
"there is an apple";
if (
$pear)
{
echo 
"there is an pear";
}
else {
echo 
"there is no pear";
}
?>
Things wrong with your script:

Random User ID's
Your bound to hit a duplicate
Using a ascending user id would be better

SQL Querys
You need to put a ` before and after database, table, and column names
mysql_num_rows is slow, use a better method like count in the SQL query

POST Data
You are not checking your POST data for HTML or Quotes. Add strip_tags and addslashes to your code.
You are not checking for duplicate emails or checking to see if they are valid.

Error
Don't put the 0 or 1 in quotes for the error variable, that changes the type of the variable to a int, which is for numbers only.


I could go on for days about improvements to your code if you wish.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed