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
https://forums.phpfreaks.com/topic/180517-solved-need-sql-inserting-help/
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?

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);
   }

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);
   }

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.