Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Register page with sendmail
Old 12-23-2010, 12:53 PM Register page with sendmail
Average Talker

Posts: 22
Trades: 0
I'm currently trying to build a browser-based gaming website and I'm having problem with the registration page. I've setup the page so that it would send an email for verification purposes, the page send the email just fine but it doesn't add a new row to the 'users' table so there was no user created.
This is my register.php code
PHP Code:
<?php
function getUniqueCode($length "")
{
 
$code md5(uniqid(rand(), true));
 if (
$length != "") return substr($code0$length);
 else return 
$code;
}
$hash getUniqueCode();
    if(
$_POST) {
    
$username $_POST["username"];
    
$username preg_replace("/[^a-zA-Z0-9\\040.]/"""$username);
        
$password htmlspecialchars($_POST['password'], ENT_QUOTES);
        
$confirm htmlspecialchars($_POST['confirm'], ENT_QUOTES);    
        if(
$password != $confirm) { ?>
<span style='color:red'>Error: Passwords do not match!</span>        
<?php    } else {
require_once 
'config.php';
            
$conn mysql_connect($dbhost,$dbuser,$dbpass)
                or die (
'Error connecting to mysql');
            
mysql_select_db($dbname);
            
$query sprintf("SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('%s')",
                
mysql_real_escape_string($username));
            
$result mysql_query($query);
            list(
$count) = mysql_fetch_row($result);
            if(
$count >= 1) { ?>
<span style='color:red'>Error: that username is taken.</span>
<?php        } else {
$email $_POST['email'];
                
$query sprintf("INSERT INTO users(username,password,salt,email) VALUES ('%s','%s','%s','%s');",
                    
mysql_real_escape_string(htmlspecialchars($usernameENT_QUOTES)),
                    
mysql_real_escape_string(md5($hash.$password.$hash)),
                    
mysql_real_escape_string($hash),
                    
mysql_real_escape_string($email));
                
mysql_query($query);
                
$to $email;
                
$subject 'Konfirmasi Email';
                
$message "
<p>Terima kasih sudah mendaftarkan diri anda untuk Adoptapo. Klik link di bawah untuk mengkonfirmasi email anda.</p>
<p><a href='http://domainname.tld/confirm.php?email=
$email'>Konfirmasi</a></p>";
                
$headers 'From: webmaster@domainname.tld' "\r\n" .
                            
'Content-type: text/html; charset=iso-8859-1' "\r\n";
                
mail($to,$subject,$message,$headers);
            
?>
<span style='color:green'>Congratulations, you registered successfully! A confirmation e-mail has been sent to the address you entered.</span>
<?php
            
}    
        }
    }
?>
<form method='post' action='register.php'>Username: <input type='text' name='username' /><br />
Password: <input type='password' name='password' /><br />
Confirm Password: <input type='password' name='confirm' /><br />
E-mail Address: <input type='text' name='email' /><br />
<input type='submit' value='Register!' />
</form>
So, what seems to be the problem?
progogi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-23-2010, 03:12 PM Re: Register page with sendmail
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Is your sprintf failing?

Try doing

if (!$query) {echo mysql_error();}
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 12-23-2010, 03:17 PM Re: Register page with sendmail
Average Talker

Posts: 22
Trades: 0
it doesn't output anything...or perhaps I put it in the wrong place?
progogi is offline
Reply With Quote
View Public Profile
 
Old 12-23-2010, 03:27 PM Re: Register page with sendmail
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Good, so it's not a mysql error.

Try echoing out each of the fields you are adding. Maybe one of them is blank when the field is set to NOT NULL?
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 12-23-2010, 04:04 PM Re: Register page with sendmail
Average Talker

Posts: 22
Trades: 0
Everything seems to be just fine, the problem appears after I added the email confirmation system.

Also, I just notice this when I open phpMyAdmin
Quote:
Your PHP MySQL library version 5.0.19 differs from your MySQL server version 5.5.8. This may cause unpredictable behavior.
Could this be the problem?

Last edited by progogi; 12-24-2010 at 07:55 AM..
progogi is offline
Reply With Quote
View Public Profile
 
Old 12-24-2010, 07:54 AM Re: Register page with sendmail
Average Talker

Posts: 22
Trades: 0
Bump...
progogi is offline
Reply With Quote
View Public Profile
 
Old 12-24-2010, 12:09 PM Re: Register page with sendmail
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by progogi View Post
Everything seems to be just fine, the problem appears after I added the email confirmation system.

Also, I just notice this when I open phpMyAdmin

Could this be the problem?
Probably not.

Print out the SQL query and post it here
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-24-2010, 06:43 PM Re: Register page with sendmail
Average Talker

Posts: 22
Trades: 0
I test the code on another server and it's working just fine.
So it must be a server problem
progogi is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Register page with sendmail
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27006 seconds with 12 queries