Jump to content

Recommended Posts

Well, after many hours of trying to debug this and then coding other stuff to come back to it I finally added the  or die(mysql_error()); and found my error.

 

So here are the sections which are at question for this code.

 

Edit::  In Process.php::

   /**
    * procRegister - Processes the user submitted registration form,
    * if errors are found, the user is redirected to correct the
    * information, if not, the user is effectively registered with
    * the system and an email is (optionally) sent to the newly
    * created user.
    */
   function procRegister(){
      global $session, $form;
      /* Convert username to all lowercase (by option) */
      if(ALL_LOWERCASE){
         $_POST['user'] = strtolower($_POST['user']);
      }
      /* Registration attempt */
      $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'], $_POST['name']);
      
      /* Registration Successful */
      if($retval == 0){
         $_SESSION['reguname'] = $_POST['user'];
         $_SESSION['regsuccess'] = true;
         header("Location: ".$session->referrer);
      }
      /* Error found with form */
      else if($retval == 1){
         $_SESSION['value_array'] = $_POST;
         $_SESSION['error_array'] = $form->getErrorArray();
         header("Location: ".$session->referrer);
      }
      /* Registration attempt failed */
      else if($retval == 2){
         $_SESSION['reguname'] = $_POST['user'];
         $_SESSION['regsuccess'] = false;
         header("Location: ".$session->referrer);
      }
   }

 

In DATABASE.php::

   function addNewUser($username, $password, $email, $userid, $name){
      $time = time();
      /* If admin sign up, give admin user level */
      if(strcasecmp($username, ADMIN_NAME) == 0){
         $ulevel = ADMIN_LEVEL;
      }else{
         $ulevel = USER_LEVEL;
      }
      $q = "INSERT INTO ".TBL_USERS." VALUES ('','$username', '$password', '$userid', $ulevel, '$email', $time, '0', '$name')";
      return mysql_query($q, $this->connection) or die(mysql_error());  //This is here temporarily.
   }

 

I'm relatively sure this is the portion which the problem is located in.

 

So we have the following Variables.    1: empty, 2: $username, 3: $password, 4: $userid, 5: $ulevel, 6: $email, 7:$time, 8: 0, 9: $name

My Table Layout is relatively similar.    1: uid, 2: username, 3: password, 4: userid, 5: userlevel, 6: email, 7: timestamp, 8: valid, 9: name

 

I figured if I put in the ' ', at the beginning of the query, that it would actually work out.  Unfortunately it doesn't want to allow for my uid to be there.

 

UID: This is an auto-incrementing number which is in no way affected by the website, nor any queries.  This number is to be used in order to gather similar information required about the same user from multiple tables.

 

UserID:  Randomly generated Session ID that enables it to be stored in Cookies to validate a session.  This is an advanced security feature which keeps passwords out of cookies, pretty nifty huh?

 

I didn't create this code, it's from JPMaster77's Login Advanced 2.0 or what not.  I'm just trying to use it.

 

So taken the Column count doesn't match value count at row one, I'm guessing it is trying to stick something in there that isn't being told to?

 

I dunno, this one has had me stumped all day.  Let me know if anyone can help out with this.

 

Thanks in advance, and if this site still does rep... I will rep you upon solved status, or on extensive knowledge. 

 

"""I should hire one of them there programmen guys to do all my programmens and stuff, shouldn't I?"""

INSERT INTO tablename VALUES (...) requires you to provide a value for every column in the table, in the order they exist in the table.  It looks like you tried to take care of that by adding the '' as the first value.  Unfortunately, an empty string is not a valid value for a numeric field (which is what your UID is).  So you get an error.  If you insist on not listing the columns in the input statement, then put the word NULL there (not in quotes).

 

Personally, I always name the columns so the code is clearer when I review it later.  Also, if the table structure changes later, the insert will not fail because the column count is always correct.  If you name the columns, you do not have to provide a value for the auto_increment column:

INSERT INTO mytable (column1, column2, column3) 
VALUES (25, 'something', 'end of line.');

AHAH!!  AT LAST!

      $q = "INSERT INTO ".TBL_USERS." (username, password, userid, userlevel, email, timestamp, valid, name) VALUES ('$username', '$password', '$userid', $ulevel, '$email', $time, '0', '$name')";

 

It was never an insist thing, I was taking code that was written by someone else and trying to make it do what I wanted.  I did however finally figure out what you was talking about, once I saw your example.

 

Thank you in an inconceivable amount, I owe you more than just a debt of gratitude.  Also, you can see my tables are named quite nicely.

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.