News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

call up another db and editing it

Started by Hot Rides, April 09, 2008, 09:22:45 AM

Previous topic - Next topic

rsw686

Quote from: Hot Rides on April 10, 2008, 08:53:44 PM
The coding has to be done to SMF to tell it to access and edit the Coppermine DB.

Actually the coding should go in the bridge file which is part of coppermine.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Hot Rides

could you explain further? Im in over my head here.

rsw686

In the coppermine\bridge folder there is smf10.inc.php. This is the bridge file to interface SMF and Coppermine. This files provides the needed functions to link the two programs. You would want to add the album creation code in here.

First check to see if they have an album with the SQL query

SELECT aid FROM cpg_albums WHERE category = [10000 + SMF USER ID]

If mysql_num_rows = 0 then add an album for that user

INSERT INTO cpg_albums (title, category)
VALUES ('My album', [10000 + SMF USER ID])

I would probably stick this code in the  function authenticate() right before the                 $this->session_update().

Make sure to check to see if they are logged in. You don't want to add albums for guests. A simple $user_settings['ID_MEMBER'] != 0 would work.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Kindred

you probably want an IF NOT EXISTS in there as well...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Hot Rides

thank you for the help, I will see if this works and report back

Hot Rides

it does not like my code, did I do something wrong?
$request = db_query("
SELECT aid
FROM {$db_prefix}albums
WHERE category = [10000 + ['username']]");

If (mysql_num_rows($request) = 0 ;

INSERT INTO {$CONFIG['TABLE_ALBUMS']}  (title, category)
VALUES ('My album', [10000 + ['username']]);

rsw686

#26
You need to be using the coppermine functions to run the query. Also the formatting of your code is not correct. My previous post was just an explanation of what to do, not a copy paste. ;)

I haven't tested this so there could be some things that need slight tweaking.


if($user_settings['ID_MEMBER'] != 0)
{
$sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = " . (10000 + $user_settings['ID_MEMBER']);
$result = cpg_db_query($sql, $this->link_id);
if(mysql_num_rows($result) == 0)
{
$sql = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (title, category) VALUES ('My album', " . (10000 + $user_settings['ID_MEMBER']) . ")";
cpg_db_query($sql, $this->link_id);
}
mysql_free_result($result);
}
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Hot Rides

fatal error

I do not have the time to search right now for more answer, Im off to bed, any ideas would be helpful. Thank you with the help in the code so far I am slowly learning.

rsw686

Quote from: Hot Rides on April 12, 2008, 12:43:33 AM
fatal error

I do not have the time to search right now for more answer, Im off to bed, any ideas would be helpful. Thank you with the help in the code so far I am slowly learning.

What line was the error on? You can add the below line to your .htaccess file to show the errors.

php_value display_errors on

If I have time later I'll setup another gallery install and get you the exact code. I just don't want to be messing with this on my live site.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

rsw686

This is an easy fix. I didn't see that $CONFIG wasn't included in the globals. At the top of the authenticate function change

global $USER_DATA, $user_settings;

to

global $USER_DATA, $user_settings, $CONFIG;

Works perfectly now. It created a "My album" automatically for my test user.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts


rsw686

Quote from: Hot Rides on April 12, 2008, 02:02:18 AM
didnt work :(

I have it working on a cleanly bridge coppermine and smf 1.1.4 install. Try my bridge file

http://wgnrs.dynalias.com/smf/smf10.inc.php
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Hot Rides

Quote from: rsw686 on April 12, 2008, 07:48:16 AM
Quote from: Hot Rides on April 12, 2008, 02:02:18 AM
didnt work :(

I have it working on a cleanly bridge coppermine and smf 1.1.4 install. Try my bridge file

http://wgnrs.dynalias.com/smf/smf10.inc.php
Still 'fatal error'
Right before this I updated Coppermine to 1.4.17 for a sercuity update and Im also running Stramm's Modpak on it. That might be interfering as well.

rsw686

#33
The best way to debug the fatal error message, since it doesn't give a line number, is to insert some echo statements so you can narrow down which one is causing the fatal error.

The test site I have is running 1.4.16. I'll try updating it to 1.4.17 and seeing if that is the issue. Not sure about Stramm's Modpak.

EDIT: Just tried out 1.4.17. No problems with the above bridge file I provided you.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Hot Rides


Hot Rides

While executing query "SELECT aid FROM cpg_albums WHERE category = 10001" on Resource id #27

mySQL error: No database selected

Hot Rides


if($user_settings['ID_MEMBER'] != 0){
$sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = " . (10000 + $user_settings['ID_MEMBER']) ;
$result = cpg_db_query($sql, $this->link_id);

I did some research and this is causing the error, it never makes it to the rest of the code before crashing

rsw686

Right the error is from the database not being selected when the sql connection is made. However I don't see how that is possible as the class constructor initializes the database connection.  I've tested the code I supplied on two different gallierys and it worked on both. The only thing I can think of is a mod on your gallery is contributing to the problem.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Hot Rides

did either of them have stramms modpack?

rsw686

Quote from: Hot Rides on April 16, 2008, 04:09:47 PM
did either of them have stramms modpack?

Nope, can you give me a download link to that.
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Advertisement: