1
jilong
how to write value into database new field?
  • 2007/2/2 7:49

  • jilong

  • Just popping in

  • Posts: 61

  • Since: 2007/1/10


I know now there have a module "smartprofile" to add the extra field for registration, but because i am not using php5, so i have do it in my way.

i have use phpmyadmin to created a new fields in xoops_users. (user_uni and user_grade)

in edituser.php i have add in this few lines:
$edituser->setVar('user_uni'$_POST['user_uni']);

$edituser->setVar('user_grade'$_POST['user_grade']);


$uni_text = new XoopsFormText(_US_UNI'user_uni'3050$xoopsUser->getVar('user_uni''E'));

$grade_text = new XoopsFormText(_US_GRADE'user_grade'3050$xoopsUser->getVar('user_grade''E'));


     
$form->addElement($uni_text);
     
$form->addElement($grade_text);


i have also add some code in /kernel/user.php

$this->initVar('user_uni'XOBJ_DTYPE_TXTBOXnulltrue60);
     
$this->initVar('user_grade'XOBJ_DTYPE_TXTBOXnulltrue60);



    function 
user_uni($format="S")
    {
        return 
$this->getVar("user_uni"$format);
    }  
    

    function 
user_grade($format="S")
    {
        return 
$this->getVar("user_grade"$format);
    }   


 
// Added two fields, notify_method, notify_mode
        
if ($user->isNew()) {
            
$uid $this->db->genId($this->db->prefix('users').'_uid_seq');
            
$sql sprintf("INSERT INTO %s (user_uni, user_grade) VALUES (%s, %s)"$this->db->prefix('user_uni'), $uid$this->db->quoteString('user_grade'));
        } else {
            
$sql sprintf("UPDATE %s SET user_uni = %s, user_grade = %s"$this->db->prefix('user_uni'), $this->db->quoteString('user_grade'));
        }


with this way i can't write the value into database, but i try to add the value from database it able call the value, is there i miss up any?

2
zyspec
Re: how to write value into database new field?
  • 2007/2/2 14:08

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


Currently your code inside /kernel/user.php looks like:
if ($user->isNew()) {
     
$uid $this->db->genId($this->db->prefix('users').'_uid_seq');
     
$sql sprintf("INSERT INTO %s (user_uni, user_grade) VALUES (%s, %s)"$this->db->prefix('user_uni'), $uid$this->db->quoteString('user_grade'));
} else {
     
$sql sprintf("UPDATE %s SET user_uni = %s, user_grade = %s"$this->db->prefix('user_uni'), $this->db->quoteString('user_grade'));
}


but I believe you should have changed it to something like:
if ($user->isNew()) {
    
$uid $this->db->genId($this->db->prefix('users').'_uid_seq');
    
$sql sprintf("INSERT INTO %s (uid, uname, name, email, url, user_avatar, user_regdate, user_icq, user_from, user_sig, user_viewemail, actkey, user_aim, user_yim, user_msnm, pass, posts, attachsig, rank, level, theme, timezone_offset, last_login, umode, uorder, notify_method, notify_mode, user_occ, bio, user_intrest, user_mailok, user_uni, user_grade) VALUES (%u, %s, %s, %s, %s, %s, %u, %s, %s, %s, %u, %s, %s, %s, %s, %s, %u, %u, %u, %u, %s, %.2f, %u, %s, %u, %u, %u, %s, %s, %s, %u, %s, %s)"$this->db->prefix('users'), $uid$this->db->quoteString($uname), $this->db->quoteString($name), $this->db->quoteString($email), $this->db->quoteString($url), $this->db->quoteString($user_avatar), time(), $this->db->quoteString($user_icq), $this->db->quoteString($user_from), $this->db->quoteString($user_sig), $user_viewemail$this->db->quoteString($actkey), $this->db->quoteString($user_aim), $this->db->quoteString($user_yim), $this->db->quoteString($user_msnm), $this->db->quoteString($pass), $posts$attachsig$rank$level$this->db->quoteString($theme), $timezone_offset0$this->db->quoteString($umode), $uorder$notify_method$notify_mode$this->db->quoteString($user_occ), $this->db->quoteString($bio), $this->db->quoteString($user_intrest), $user_mailok,$this->db->quoteString($user_uni), $this->db->quoteString($user_grade);
} else {
    
$sql sprintf("UPDATE %s SET uname = %s, name = %s, email = %s, url = %s, user_avatar = %s, user_icq = %s, user_from = %s, user_sig = %s, user_viewemail = %u, user_aim = %s, user_yim = %s, user_msnm = %s, posts = %d,  pass = %s, attachsig = %u, rank = %u, level= %u, theme = %s, timezone_offset = %.2f, umode = %s, last_login = %u, uorder = %u, notify_method = %u, notify_mode = %u, user_occ = %s, bio = %s, user_intrest = %s, user_mailok = %u, user_uni = %s, user_grade = %s WHERE uid = %u"$this->db->prefix('users'), $this->db->quoteString($uname), $this->db->quoteString($name), $this->db->quoteString($email), $this->db->quoteString($url), $this->db->quoteString($user_avatar), $this->db->quoteString($user_icq), $this->db->quoteString($user_from), $this->db->quoteString($user_sig), $user_viewemail$this->db->quoteString($user_aim), $this->db->quoteString($user_yim), $this->db->quoteString($user_msnm), $posts$this->db->quoteString($pass), $attachsig$rank$level$this->db->quoteString($theme), $timezone_offset$this->db->quoteString($umode), $last_login$uorder$notify_method$notify_mode$this->db->quoteString($user_occ), $this->db->quoteString($bio), $this->db->quoteString($user_intrest), $user_mailok$uid),$this->db->quoteString($user_uni), $this->db->quoteString($user_grade));
}


NOTE: I didn't test this code to verify it works so please check it closely - and as always MAKE A BACKUP OF EVERYTHING BEFORE YOU ATTEMPT NEW CODE.

The idea here is that the original code created (or updated) the user record fields. Your code did not create all the fields - including your new ones. I'm surprised you didn't get a SQL error. Make sure when you're writing/debugging new code to turn on XOOPS debug in Admin.

3
jilong
Re: how to write value into database new field?
  • 2007/2/4 6:39

  • jilong

  • Just popping in

  • Posts: 61

  • Since: 2007/1/10


actually i did to create all fields,
here is the full set coding in kernel/user.php. this time i only test with 1 field "cor_adds" $this->db->quoteString($cor_adds), with this i have no any sql error, but i still can;t update the field. as i said if i add in the value from PhpMyadmin the value will appear on userinfo.php but just can't update it. is there anyother file i need to change code?


if ($user->isNew()) {
            
$uid $this->db->genId($this->db->prefix('users').'_uid_seq');
            
$sql sprintf("INSERT INTO %s (uid, uname, name, email, url, user_avatar, user_regdate, user_icq, user_from, user_sig, user_viewemail, actkey, user_aim, user_yim, user_msnm, pass, posts, attachsig, rank, level, theme, timezone_offset, last_login, umode, uorder, notify_method, notify_mode, user_occ, bio, user_intrest, cor_adds, user_mailok) VALUES (%u, %s, %s, %s, %s, %s, %u, %s, %s, %s, %u, %s, %s, %s, %s, %s, %u, %u, %u, %u, %s, %.2f, %u, %s, %u, %u, %u, %s, %s, %s, %s, %u)"$this->db->prefix('users'), $uid$this->db->quoteString($uname), $this->db->quoteString($name), $this->db->quoteString($email), $this->db->quoteString($url), $this->db->quoteString($user_avatar), time(), $this->db->quoteString($user_icq), $this->db->quoteString($user_from), $this->db->quoteString($user_sig), $user_viewemail$this->db->quoteString($actkey), $this->db->quoteString($user_aim), $this->db->quoteString($user_yim), $this->db->quoteString($user_msnm), $this->db->quoteString($pass), $posts$attachsig$rank$level$this->db->quoteString($theme), $timezone_offset0$this->db->quoteString($umode), $uorder$notify_method$notify_mode$this->db->quoteString($user_occ), $this->db->quoteString($bio), $this->db->quoteString($user_intrest), $this->db->quoteString($cor_adds), $user_mailok);
        } else {
            
$sql sprintf("UPDATE %s SET uname = %s, name = %s, email = %s, url = %s, user_avatar = %s, user_icq = %s, user_from = %s, user_sig = %s, user_viewemail = %u, user_aim = %s, user_yim = %s, user_msnm = %s, posts = %d,  pass = %s, attachsig = %u, rank = %u, level= %u, theme = %s, timezone_offset = %.2f, umode = %s, last_login = %u, uorder = %u, notify_method = %u, notify_mode = %u, user_occ = %s, bio = %s, user_intrest = %s, cor_adds = %s, user_mailok = %u WHERE uid = %u"$this->db->prefix('users'), $this->db->quoteString($uname), $this->db->quoteString($name), $this->db->quoteString($email), $this->db->quoteString($url), $this->db->quoteString($user_avatar), $this->db->quoteString($user_icq), $this->db->quoteString($user_from), $this->db->quoteString($user_sig), $user_viewemail$this->db->quoteString($user_aim), $this->db->quoteString($user_yim), $this->db->quoteString($user_msnm), $posts$this->db->quoteString($pass), $attachsig$rank$level$this->db->quoteString($theme), $timezone_offset$this->db->quoteString($umode), $last_login$uorder$notify_method$notify_mode$this->db->quoteString($user_occ), $this->db->quoteString($bio), $this->db->quoteString($user_intrest), $this->db->quoteString($cor_adds), $user_mailok$uid);
        }


where can i turn on XOOPS debug in admin?

4
jilong
Re: how to write value into database new field?
  • 2007/2/4 8:23

  • jilong

  • Just popping in

  • Posts: 61

  • Since: 2007/1/10


i think i found the problem already. but now i got another problem, i get the was able to write the date value into database, but when i try to edituser, the date field will call back to the default value which is 1970-01-01

Here is the code i add in kernel/user.php


$this->initVar('dob', XOBJ_DTYPE_OTHER, null, false);



function dob($format="S")
{
return $this->getVar("dob", $format);
}



$sql sprintf("UPDATE %s SET uname = %s, name = %s, email = %s, url = %s, user_avatar = %s, user_icq = %s, user_from = %s, user_sig = %s, user_viewemail = %u, user_aim = %s, user_yim = %s, user_msnm = %s, posts = %d,  pass = %s, attachsig = %u, rank = %u, level= %u, theme = %s, timezone_offset = %.2f, umode = %s, last_login = %u, uorder = %u, notify_method = %u, notify_mode = %u, user_occ = %s, bio = %s, user_intrest = %s, user_mailok = %u, cor_adds = %s, cor_post = %s, user_group = %s, tel_hp = %s, home_adds = %s, home_post = %s, tel_home = %s, dob = %s WHERE uid = %u"$this->db->prefix('users'), $this->db->quoteString($uname), $this->db->quoteString($name), $this->db->quoteString($email), $this->db->quoteString($url), $this->db->quoteString($user_avatar), $this->db->quoteString($user_icq), $this->db->quoteString($user_from), $this->db->quoteString($user_sig), $user_viewemail$this->db->quoteString($user_aim), $this->db->quoteString($user_yim), $this->db->quoteString($user_msnm), $posts$this->db->quoteString($pass), $attachsig$rank$level$this->db->quoteString($theme), $timezone_offset$this->db->quoteString($umode), $last_login$uorder$notify_method$notify_mode$this->db->quoteString($user_occ), $this->db->quoteString($bio), $this->db->quoteString($user_intrest), $user_mailok$this->db->quoteString($cor_adds), $this->db->quoteString($cor_post), $this->db->quoteString($user_group), $this->db->quoteString($tel_hp), $this->db->quoteString($home_adds), $this->db->quoteString($home_post), $this->db->quoteString($tel_home), $this->db->quoteString($dob), $uid);
        }

Login

Who's Online

209 user(s) are online (117 user(s) are browsing Support Forums)


Members: 1


Guests: 208


Mamba,

more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Oct 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits