Jump to content

[SOLVED] Need sql inserting help


thenewperson

Recommended Posts

Trying to add this code into database but i dont understand this script that well and keep failing. Trying to add $folder into data base field folder where the username is when they register

$folderid = md5(uniqid(rand()));
$folder = substr($id, 0, 10);

 

function addNewUser($username, $password, $email){
      $time = time();
  $database->updateUserField($this->username, "folder", $this->$folder);
      /* 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', '0', $ulevel, '$email', $time)";
  
      return mysql_query($q, $this->connection);
   }

 

 

full login system is here

http://evolt.org/node/60384

 

 

Link to comment
Share on other sites

Wow that is one moldy tutorial.  It uses addslashes and stripslashes instead of mysql_real_escape_string.

 

You are waaay off base with what you're doing.  To tell you how to fix it entirely, i'd need to understand more about what the folder value is.  Is this a new column you added to the Users table?  If so, you'd simply add that as a param to this method, and to the insert.

 

Needless to say your current code won't work, not only because of the numerous syntax errors and misunderstanding of $this->, but also because if you look at what you're doing -- how could you attempt to update a value in a row, where you haven't even inserted the row for the user yet?

Link to comment
Share on other sites

Typed the wrong line in on accident from something else this is what it was

 

function addNewUser($username, $password, $email){
      $time = time();
$folderid = md5(uniqid(rand()));
$folder = substr($id, 0, 10);
      /* 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', '0', $ulevel, '$email', $time, $folder)";
  
      return mysql_query($q, $this->connection);
   }

Link to comment
Share on other sites

You have a pretty obvious error with your temp variables.  There's really no reason to make a temp variable called folderid, just so you can substr() it.  Do it in one line.

 

Again -- this assumes that you have added a folder column to the users table and it's the last column after the time.

 

function addNewUser($username, $password, $email){
      $time = time();      
      $folder = substr(md5(uniqid(rand())), 0, 10);

      /* 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', '0', $ulevel, '$email', $time, $folder)";
    
      return mysql_query($q, $this->connection);
   }

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.