11
m0nty
Re: Database tables -- insert codes
  • 2006/2/10 4:31

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


wtravel posted for XOOPS 2.0.13.2 unfortunately..

xoops 2.2.4 is somewhat different, i dunno how to do it with 2.2 tho.. sorry.

12
wtravel
Re: Database tables -- insert codes

Ah, sorry... I had a look into 2.2.3 and in the file:

modules/profile/register.php

look for the line: $newid = $newuser->getVar('uid');

Below that line insert
//Insert user into PCPIN table
$sql = sprintf("INSERT INTO %s (uname_field, email_field, pass_field) VALUES (%s, %s, %s)", $this->db->prefix('other_table_name'), $newuser->getvar('uname'), $newuser->getvar('email'), $newuser->getvar('pass'));
$result = $xoopsDB->query($sql);
You will need to change the database name and fieldnames again.

I did not test it because I did not install a 2.2.3 version on my PC, but you can give this a try and let me know if it works or not .

Edited: 2.2.4 did not change regarding the insertion of a user.

13
RSearcy
Re: Database tables -- insert codes
  • 2006/2/10 14:35

  • RSearcy

  • Just popping in

  • Posts: 45

  • Since: 2004/3/2 2


It's not working, unfortunately. I get this error:

Fatal error: Call to a member function prefix() on a non-object in /home/grtest/public_html/xoops/modules/profile/register.php on line 156
Notice 
[PHP]: Undefined variable: grtest_i155xoo in file modules/profile/register.php line 156

Here's the code I put in, so you can see what I did wrong (which is obvious lol) -- oh, BTW, in addition to XOOPS 2.2.3, I'm also running PHP 5.0.5 and MySQL 4.1.13-standard if y'all needed to know that:
//Insert user into PCPIN table
        
$sql = sprintf("INSERT INTO %s (login, email, password) VALUES (%s, %s, %s)", $grtest_i155xoo->prefix('pcpin_user'), $newuser->getvar('uname'), $newuser->getvar('email'), $newuser->getvar('pass'));
        
$result = $grtest_i155xoo->query($sql);

14
wtravel
Re: Database tables -- insert codes

The key is to get the correct database handler class.

Try and replace $grtest_i155xoo with $xoopsDB in both lines.

15
RSearcy
Re: Database tables -- insert codes
  • 2006/2/10 15:04

  • RSearcy

  • Just popping in

  • Posts: 45

  • Since: 2004/3/2 2


Still not working, however, I no longer get an error message when registering (and I still have PHP debug turned on). It registers in the xoops_users but not the pcpin_user.

//Insert user into PCPIN table
        
$sql = sprintf("INSERT INTO %s (login, email, password) VALUES (%s, %s, %s)", $xoopsDB->prefix('pcpin_user'), $newuser->getvar('uname'), $newuser->getvar('email'), $newuser->getvar('pass'));
        
$result = $xoopsDB->query($sql);

16
wtravel
Re: Database tables -- insert codes

Can you check which error the query comes up with?
You can add the errorhandler functionality by adding two lines and changing the last line.

include_once XOOPS_ROOT_PATH."/class/module.errorhandler.php";
$eh = new ErrorHandler;
$result = $xoopsDB->query($sql) or $eh->show("0013");

17
RSearcy
Re: Database tables -- insert codes
  • 2006/2/10 15:47

  • RSearcy

  • Just popping in

  • Posts: 45

  • Since: 2004/3/2 2


Error Code: 0013


ERROR
: Could not query the database. 
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2, grtest2@grtest2.robertsearcy.info, 284ffbecc619c5d27f3e0067e22e30c1)' at line 1

I noticed something too when I looked at that error code.....it's cutting off the 1st part of the username.

The username I had registered with was User2 (because I'm doing test users to test out not only this but other stuff too from a normal user standpoint before I make a "final draft" of the site.

18
wtravel
Re: Database tables -- insert codes

I am not sure what why this is not working yet. What you could do to find out what causes the problem is to add a few echo commands.

add these lines
echo $newuser->getVar('uname')." is supposed to be the usename<br />";
echo 
$sql;
before the line:
$result = $xoopsDB->query($sql) or $eh->show("0013");

It will show you the username that is supposed to be safed and it will show you the full sql code for the INSERT query.

19
RSearcy
Re: Database tables -- insert codes
  • 2006/2/10 17:28

  • RSearcy

  • Just popping in

  • Posts: 45

  • Since: 2004/3/2 2


grnet2 is supposed to be the username
INSERT INTO xoops_pcpin_user 
(login, email, password) VALUES (grnet2, grtest2@grtest2.robertsearcy.info, 284ffbecc619c5d27f3e0067e22e30c1)
Golden-Road.net Error

Error Code
: 0013


ERROR
: Could not query the database. 
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@grtest2.robertsearcy.info, 284ffbecc619c5d27f3e0067e22e30c1)' at line 1

There ya go. Still, I don't know what could be wrong. I'm glad there's people like you around to help.

Edit: OOOOOOOOHHHHHH WAIT! I see what's up. It's trying to insert it into "xoops_pcpin_user". It's trying to insert the data into the wrong table (a non-existant one). How would I fix that?

20
wtravel
Re: Database tables -- insert codes

I hope this was the problem. Started to run out of options (almost).
$sql = sprintf("INSERT INTO %s (login, email, password) VALUES (%s, %s, %s)", 'pcpin_user', $newuser->getvar('uname'), $newuser->getvar('email'), $newuser->getvar('pass'));

Looking forward to see if it that does the trick or not.

For reference, the $xoopsDB->prefix() function adds the prefix XOOPS uses for its tables.