Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2012, 10:51 PM   PM User | #1
ershy
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
ershy is an unknown quantity at this point
Registration code

The code for posting registration info to the database dies and does not display an error.

PHP Code:
<?php 
include_once("scripts/connect_to_mysql.php");
$message ='';

if(isset(
$_POST['username'])){

    
$username $_POST['username'];
    
$fname $_POST['fname'];
    
$lname $_POST['lname'];
    
$email $_POST['email'];
    
$pass1 $_POST['pass1'];
    
$pass2 $_POST['pass2'];
    
    
//error handling
    
if((!$username)||(!$fname)||(!$lname)||(!$email)||(!$pass1)||(!$pass2)){
        
$message='Please insert all fields into the form below.';
    }else{
        if(
$pass1 != $pass2){
            
$message ='Your password fields do not match.';
        }else{
            
//securing the values of the variables
            
$username preg_replace("#[^0-9a-z]#i","",$username);
            
$fname preg_replace("#[^0-9a-z]#i","",$fname);
            
$lname preg_replace("#[^0-9a-z]#i","",$lname);
            
$pass1 sha($pass1);
            
$email mysql_real_escape_string($email);
            
            
//check duplicates
            
$user_query mysql_query("SELECT username FROM members WHERE username='$username' LIMIT 1")or die("Could not check username");
            
$count_username mysql_num_rows($user_query);
            
            
$user_query mysql_query("SELECT email FROM members WHERE email='$email' LIMIT 1")or die("Could not check Email");
            
$count_email mysql_num_rows($email_query);
            
            if(
$count_username 0){
                
$message ='Your username already exists.';
            }else if(
$count_email 0){
                
$message ='Your email already exists.';
            }else{
                
// insert users
                
$query mysql_query("INSERT INTO members (username, fname, lname, email, password, lastlogin, accounttype, emailactivated, joindate) VALUES('$username', '$fname', '$lname', '$email', '$password', '', '', '', now())")or die("Could not insert data.");
                
$member_id mysql_insert_id();
                
mkdir("users/$member_id",0755);
                
$message ='You have now been registered.';
            }
        }
?>
body section
Code:
<div>
Register to my site by filling in the fields below.
	<p><?php print("$message");?></p>
	<form action="register2.php" method="post">
		<input type="text" name="username" placeholder="Username"/><br />
        <input type="text" name="fname" placeholder="First Name"/><br />
        <input type="text" name="lname" placeholder="Last Name"/><br />
        <input type="text" name="email" placeholder="Email Address"/><br />
        <input type="password" name="pass1" placeholder="Password"/><br />
        <input type="password" name="pass2" placeholder="Validate your password"/><br />
        <input type="submit" value="Register" />


	</form>
</div>

Last edited by ershy; 11-14-2012 at 01:07 AM..
ershy is offline   Reply With Quote
Old 11-14-2012, 12:03 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You don't have an entry called user in your form. You'll never pass the first isset check without it. Isset should be given every item you expect to be provided with to verify they exist prior to useing them.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
ershy (11-14-2012)
Old 11-14-2012, 01:03 AM   PM User | #3
ershy
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
ershy is an unknown quantity at this point
Thanks! I changed
PHP Code:
if(isset($_POST['username'])) 
but it still died without firing off the form. I'm still a bit confused.

Last edited by ershy; 11-14-2012 at 02:18 AM..
ershy is offline   Reply With Quote
Old 11-14-2012, 01:29 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Now you add a print. Currently the script generates no output so you cannot tell where you ended up. Add print $message; to the bottom of the script.
Fou-Lu is offline   Reply With Quote
Old 11-14-2012, 01:41 PM   PM User | #5
ershy
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
ershy is an unknown quantity at this point
I actually have a print at the top of the form. When I load the page on the server though, it never loads the form or the print.
ershy is offline   Reply With Quote
Old 11-14-2012, 04:49 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I'm not talking about a print on the form, I'm talking about a print on the processing script register2.php. No matter the outcome of the script, it produces no output.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
error, form, mysql, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 08:28 AM.


Advertisement
Log in to turn off these ads.