Jump to content

[SOLVED] Register Script


spamoom

Recommended Posts

I have this function, it shows when i have errors but for some reason is never able to reach the insert query.. here is the code. I suspect it is a typo, please could you have a look for me as I have been searching for over an hour and cant find anything  :(

 

<?php
function register($username, $password, $password_conf, $email, $email_conf) {

if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($username))) ) {
	$query = "SELECT member_username FROM member WHERE member_username = '$username'";
      $result = @$db->query($query);
      $num = @$db->count($result);
     
      if ($num> 0) {
	  $errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';
      }
  } else {
      $errors[] = '<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
  }
  
  if (!empty($email)) {
	  if ($email != $email_conf) {
		  $errors[] = '<font color="red">The email addresses you have entered do not match.</font>';
	  }
	  if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}', stripslashes(trim($email)) )) {
		  $errors[] = '<font color="red">Please provide a valid email address.</font>';
	  }
  } else {
              $errors[] = '<font color="red">Please provide an email.</font>';
          }
	  
  
      if (!empty($password)) {
              if ($password != $password_conf) {
                  $errors[] = '<font color="red">The passwords you have entered do not match.</font>';
              } else {
                  $password = md5($password);
              }
          } else {
              $errors[] = '<font color="red">Please provide a password.</font>';
          }
      if (!isset($errors)) {
              $query = "INSERT INTO member (member_username, member_email, member_password, member_joindate) VALUES ('$username', '$email', '$password', '".date('d-m-Y')."')";
             echo $query;
              $result = @mysql_query($query);
             
              if (mysql_affected_rows() == 1) {
       
                              // Send the E-Mail
                              $body = "Thank You for registering on The Revision Shop:\n\n";
                      $body .= "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?p=activate&a=" . mysql_insert_id() . "&b=$password";
                  mail($email, 'Registration Confirmation On The Revision Shop', $body, 'From: noreply@therevisionshop.co.uk');       
                              // Show thank you message
		      return 'Sucessfully Registered, Please check your mail box for the activation email';
              } else {
                  return '<font color="red">You could not be registered, please contact sam@samjordan.co.uk for help.</font>';
              }
      } else {
              $err = '<h3>Error!</h3>
              The following error(s) occured:<br />';
              foreach ($errors as $msg) {
                  $err .= " - <font color='red'>$msg</font><br />\n";
              }
      return $err;
      
          }
}
?>

Link to comment
Share on other sites

The mysql works fine, I have a login & logout script working. It is just that the script never reaches the insert statment. I have even tried putting

echo "AKDSOAWKDPAWKPDKAWJDAWJODJPWJPJ";

and it does not show at all anywhere in the script expect at the beginning =/

Link to comment
Share on other sites

why don't you take out parts of it out and test it?

 

YOu don't need the whole code to test it out. Maybe you'll find one error is somehow screwing up the code. You must take the "@"s out. It makes all the errors not shown. - which is bad at this time. For instance, no error is shown but the script is stopped... :-\

Link to comment
Share on other sites

Thanks for the replys guys :D

 

I recieved this nice error after removing the @'s

 

Fatal error: Call to a member function query() on a non-object in C:\Users\SpaM!\Desktop\localhost\therevisionshop\app\framework\functions.php on line 44

 

So in otherwords... I forgot this

global $db;

 

:P stupid me  :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.