PDA

View Full Version : Help with an SQl query please


Jolten
07-26-2004, 08:19 AM
I've got a table in my database named usrcredit.

This table has two fields, usrname and curcredit

The usrname field matches the usernames of all forum members I've given or awarded "credits" to. The curcredit field indicates their current amount of credits.

I'm trying to call this value on a page so that it can be included in Vbulletin pages and I'm hitting a snag somewhere in my query.

here's the query:


$DB_site->query("SELECT curcredit as curcredit FROM usrcredit WHERE usrname=$bbuserinfo[username]");
$credit = $bbuserinfo[curcredit];


it's generating this error:
Fatal error: Call to a member function on a non-object in /home/www/domainname/bb/test.php on line 8

if I change the query to:

$DB_site->query("SELECT curcredit as curcredit FROM usrcredit WHERE usrname=$bbuserinfo['username']");
$credit = $bbuserinfo[curcredit];


it generates this error:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/www/domainname/bb/test.php on line 8


Line 8 is the query.

Any help would be GREATLY appreciated.

Thanks.

Colin F
07-26-2004, 08:43 AM
try

$creditinfo = $DB_site->query_first("SELECT curcredit FROM usrcredit WHERE usrname='$bbuserinfo[username]'");
$credit = $creditinfo[curcredit];

Also, if you're not to far with coding yet, it might make sense to change username to userid, as that would stop some potential problems with funny characters in usernames.

Jolten
07-26-2004, 08:47 AM
Thanks Colin,

Same error though

Fatal error: Call to a member function on a non-object in /home/www/domain/bb/test.php on line 8

Colin F
07-26-2004, 08:53 AM
Thanks Colin,

Same error though

Fatal error: Call to a member function on a non-object in /home/www/domain/bb/test.php on line 8

try to either change $bbuserinfo[username] to your username or echo $bbuserinfo[username], to see if that has anything in it.

try this first, I think that's the problem
Do you have
require_once('./global.php');
somewhere at the top of your file?
If not, add that.

Jolten
07-26-2004, 08:56 AM
ahh.. that got it... Thanks a bunch Colin.

I completely spaced requiring the global.php file.

it's working now.

Thanks again! You've helped make an entire community happy :)

Colin F
07-26-2004, 09:10 AM
my pleasure :)

Jolten
07-27-2004, 08:47 PM
Okay anyone want to help with one more query?

I've got the table usrcredit in the database it has two feilds usrname and curcredit.
I'm tryign to populate these fields at registration by inserting the username and a given integer. I know the file I need to modify is register.php. The user gets added to teh vbulletin side but they reveive a general database error and nothing gets inserted into my two fields. Here's what I've tried:


$DB_site->query("INSERT INTO usrcredit (usrname) VALUES ($username)");
$DB_site->query("INSERT INTO usrcredit (curcredit) VALUES (100)");


I set those two queries to run after the unser information is created in vbulletin.

Any help would be appreciated.

Thanks

Colin F
07-27-2004, 08:50 PM
try this:
$DB_site->query("INSERT INTO usrcredit (usrname, curcredit) VALUES ('$username', '100')");

Jolten
07-27-2004, 09:08 PM
hmm.. that inserted the fields but the usrname field was blank.

Colin F
07-27-2004, 09:12 PM
OK, try changing it to:

$DB_site->query("INSERT INTO usrcredit (usrname, curcredit) VALUES ('" . addslashes(htmlspecialchars_uni($_POST['username'])) . "', '100')");

Jolten
07-27-2004, 09:12 PM
I got it.. thanks Colin.

Here's what worked:

$DB_site->query("INSERT INTO usrcredit (usrname,curcredit) VALUES ('" . addslashes(htmlspecialchars_uni($_POST['username'])) . "','100')");

I hope I can repay you at some point Colin

Jolten
07-27-2004, 09:13 PM
Cross posted :) Yup that works great! Thanks colin!