www.webdeveloper.com
Results 1 to 4 of 4

Thread: PHP Insert Problem

  1. #1
    Join Date
    May 2012
    Posts
    5

    PHP Insert Problem

    Hello, I'm having an issue with my registration code. for some reason, everything functions properly up until it gets to the actual data insertion portion of the php. It bumps me over to my error code "$errormsg = "An error has occurred. Your account was not created.";"

    Can somebody tell me why this is? I've looked it over for a few hours now.

    PHP Code:
    if ($_POST['submitbtn']){
          
    $getuser $_POST['user'];
          
    $getemail $_POST['email'];
          
    $getpass $_POST['pass'];
          
    $getverifypass $_POST['verifypass'];
          
    $lastloginip $_SERVER['REMOTE_ADDR'];
          
    $getfirstname $_POST['firstname'];
          
    $getlastname $_POST['lastname'];
          
    $getbirthmonth $_POST['birthmonth'];
          
    $getbirthday $_POST['birthday'];
          
    $getbirthyear $_POST['birthyear'];
          
    $getgender $_POST['gender'];

          if ( 
    $getuser){
                  if ( 
    $getemail){
                      if ( 
    $getpass){
                          if ( 
    $getverifypass){
                              if ( 
    $getpass === $getverifypass){
                                  if ( ( 
    strlen($getemail) >= ) && ( strstr($getemail'@') ) && ( strstr($getemail'.') ) ){                                          
                                                    require(
    'connect.php');
                                  
                            
    $query mysql_query("SELECT * FROM members415 WHERE username='$getuser'");
                            
    $numrows mysql_num_rows($query);
                            
                                if (
    $numrows == 0){
                                    
    $query mysql_query("SELECT * FROM members415 WHERE email='$getemail'");
                                    
    $numrows mysql_num_rows($query);
                                    if (
    $numrows == 0){
                                        
                                        
    $password md5(md5("salt".$getpass."salt"));
                                        
    $date date('M d, Y');
                                        
    $code md5(rand());
                                        
                                        
    mysql_query("INSERT INTO tc_members415 ('id', 'username', 'password', 'email', 'last_logindate', 'join_date', 'emailactivated', 'code', 'firstname', 'lastname', 'last_loginip', 'birthdate_month', 'birthdate_day', 'birthdate_year', 'gender', 'admin_user', 'admin_entity', 'admin_art', 'admin_galaxy', 'admin_global', 'subscription', 'character', 'pm_setting') VALUES ('', '$getuser', '$password', '$getemail', '$date', '$date', '0', '$code', '$getfirstname', '$getlastname', '$lastloginip', '$getbirthmonth', '$getbirthday', '$getbirthyear', '$getgender', '0', '0', '0', '0', '0', '30', 'None', '0')");
                                        
                                        
    $query1 mysql_query("SELECT * FROM members415 WHERE username='$getuser'");
                                        
    $numrows mysql_num_rows($query1);
                                        if (
    $numrows == 1){
                                            
                                            
    $site 'http://www.edit.com';
                                            
    $headers 'From: TC Admin <admin@edit.com>';    
                                            
    $subject 'edit: Activate your account';
                                            
    $message 'Thanks for registering your edit account. In order to use your account, you must first activate it with the following details; URL: (http://www.edit.com/activate.php) Code: ('.$code.') Click the following link to activate your account. '.$site.'/activate.php?user='.$getuser.'&code='.$code.'';    
                                            
                                            if (
    mail($getemail$subject$message$headers)){
                                            
                                            
    $errormsg "<font color='blue'>You have been registered. You must activate your account with the activation link sent to <b>$getemail</b></font>";
                                            echo 
    "$backcontent $errormsg $content.";
                                            
    $getuser '';
                                            
    $getemail '';
                                                                                    
    $_POST['submitbtn'] = '';
                                                                                    
    mysql_close();
                                            
                                            }
                                            else
                                            
    $errormsg "An error has occurred. Your activation email was not sent.";
                                                                                    echo 
    "$backcontent <font color'red'>$errormsg</font> $content";
                                                                                    
    mysql_close();
                                                                    
                                        }
                                        else
                                        
    $errormsg "An error has occurred. Your account was not created.";
                                                                            echo 
    "$backcontent <font color='red'>$errormsg</font> $content";
                                                                            
    mysql_close();
                
                                    }
                                    else 
                                    
    $errormsg "There is already a user with that email address.";
                                                                    echo 
    "$backcontent <font color='red'>$errormsg</font> $content";
                                                                    
    mysql_close();
                                    
                                }
                                else 
                                
    $errormsg "There is already a user with that username.";
                                                            echo 
    "$backcontent <font color='red'>$errormsg</font> $content";
                                
    mysql_close();
                                  }
                                  else 
                                  
    $errormsg "You must enter a valid email address to register.";
                                                    echo 
    "$backcontent <font color='red'>$errormsg</font> $content";
                                  
                              }
                              else 
                              
    $errormsg "Your passwords did not match.";
                                            echo 
    "$backcontent <font color='red'>$errormsg</font> $content";
                              
                          }
                          else 
                          
    $errormsg "You must verify your password to register.";
                                    echo 
    "$backcontent <font color='red'>$errormsg</font> $content";

                          
                      }
                      else 
                      
    $errormsg "You must enter a password to register.";
                            echo 
    "$backcontent <font color='red'>$errormsg</font> $content";
                      
                  }
                  else 
                  
    $errormsg "You must enter your email to register.";
                    echo 
    "$backcontent <font color='red'>$errormsg</font> $content";
                  
          }
          else
          
    $errormsg "You must enter your username to register.";
          echo 
    "$backcontent <font color='red'>$errormsg</font> $content";
    }
    else 

  2. #2
    Join Date
    May 2010
    Location
    Manila, Philippines
    Posts
    189
    well, based on your code, I won't be able to know if there's an error on your "INSERT INTO tc_members415...". maybe you could try adding " or die(mysql_error())" so you would know if there's an error and what error you are having on that query. Your code for that insert will be :

    PHP Code:
    mysql_query("INSERT INTO tc_members415 ('id', 'username', 'password', 'email', 'last_logindate', 'join_date', 'emailactivated', 'code', 'firstname', 'lastname', 'last_loginip', 'birthdate_month', 'birthdate_day', 'birthdate_year', 'gender', 'admin_user', 'admin_entity', 'admin_art', 'admin_galaxy', 'admin_global', 'subscription', 'character', 'pm_setting') VALUES ('', '$getuser', '$password', '$getemail', '$date', '$date', '0', '$code', '$getfirstname', '$getlastname', '$lastloginip', '$getbirthmonth', '$getbirthday', '$getbirthyear', '$getgender', '0', '0', '0', '0', '0', '30', 'None', '0')") or die(mysql_error()); 

  3. #3
    Join Date
    May 2012
    Posts
    5
    I've been looking at the code all night looking over what was correct... the issue was in the database where a unique key was set for a column that also had a default setting of "None" and all new registrants have to pass through that "None" value at first, so I disabled the unique key and will just later add a filter to replace that duty.

    Thanks!!! I've learned a lot from this...

    "Always make new mistakes." I won't be repeating this one.

  4. #4
    Join Date
    May 2010
    Location
    Manila, Philippines
    Posts
    189
    I thought so it was in the database. That's why you have to include always the mysql_error() to know what exactly is the error in database. Well, that will be charged to your experience as a developer. =)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles