It is currently Sun Apr 21, 2019 1:18 pm




Post new topic Reply to topic  [ 11 posts ] 
Adding records to another database? 
Author Message

Joined: Wed Jun 04, 2008 7:44 pm
Posts: 25
Post Adding records to another database?
I need a function that will add new records to my main database, but then also to the mailing list of my phpList program, which resides on another MySql database on the same site as the main database. How do I add this function to my Add.php page?


Thu Jul 10, 2008 2:00 pm
Profile E-mail

Joined: Fri May 09, 2008 5:38 am
Posts: 271
Location: Texas USA
Post Re: Adding records to another database?
A Few quick questions. What database are you using? What version of dbqwiksite? And do you really mean another DATABASE or simply another table in the same database? MySQL support full qualification so as long as you connect to the other database it should not be a problem. If you really mean another table then there is certainly no issue.

There are a lot of differnt ways to do this but I do the following
Image

Then the called function looks like this



function set_pack($max_id, $package,$pack_dt, $source) {
$inst = "INSERT INTO mempack ";
$inst .= " (packID, MemberID, packageID, pack_dt, pack_status, pack_notes)";
$inst .= " VALUES (NULL, '$max_id', '$package', '$pack_dt', '1', '$source')";
//echo "instr '$inst' \n <br>";
$result = @mysql_query($inst) or die("mempack insert failed");
return;
}

be sure and capture any fields you need to pass so that you have them available to do the insert.
Alternately you could simply decalre them Global instead of passing them but I find I call the same
functions from lots of places so it is easier to keep straight as passed values. If it truely is another database you would need to expand the function to perform a connect priot to the insert.

Hope this helps.


Fri Jul 11, 2008 2:59 am
Profile E-mail YIM WWW

Joined: Wed Jun 04, 2008 7:44 pm
Posts: 25
Post Re: Adding records to another database?
Thanks for the help. It is another database on the same server and not just a second table in the same database. Unix server with MySql and Apache. dbQwiksite 5 Ecommerce.

I was thinking along creating a seperate function on the Add.php page connecting to the phpList database and transferring the data thereto. I would like to know what such coding will look like?


Fri Jul 11, 2008 2:11 pm
Profile E-mail

Joined: Wed Oct 08, 2008 11:27 pm
Posts: 141
Location: UK
Post Re: Adding records to another database?
Hi

Did you get this working and if so could you share the how-to?

_________________
Thanks
Simon
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
dbQwikSite Developer Version: 5.4.0.4
cPanel Version: 11.24.4-S33268
WHM 11.24.2 - X 3.9
Apache version: 2.0.63
PHP version: 5.2.5
MySQL version: 5.0.51a-community
Operating system: Linux


Tue Nov 11, 2008 10:15 pm
Profile WWW

Joined: Wed Jun 04, 2008 7:44 pm
Posts: 25
Post Re: Adding records to another database?
Sorry, no. I convinced the client to do the adding of new members to PHpList manually.


Wed Nov 12, 2008 2:17 pm
Profile E-mail

Joined: Fri May 09, 2008 5:38 am
Posts: 271
Location: Texas USA
Post Re: Adding records to another database?
I am fairly confident that the example I posted above would do the trick with one modification. You would need to execute the connect routine to the second database in the called routine. The concept is really simple. In the orriginal add routine upon a successful add you use qsrequest to gather the data you need to build the row in the other database. Then make a call to a function that will connect to the other database, format the passed data, potential fetch and additional data needed and finally perform an insert like you would do on any table. Dont let the fact that it is another database throw you off. simply include the propper connect routine in the function to get it pointed to the correct place. For safety you might run the original connect routine again before exiting the function to make sure you are pointed back to the inital database.

function set_pack($max_id, $package,$pack_dt, $source) {

require('qs_connection.php');

$inst = "INSERT INTO mempack ";
$inst .= " (packID, MemberID, packageID, pack_dt, pack_status, pack_notes)";
$inst .= " VALUES (NULL, '$max_id', '$package', '$pack_dt', '1', '$source')";
//echo "instr '$inst' \n <br>";
$result = @mysql_query($inst) or die("mempack insert failed");
return;
}


Hope this helps
Cheers
Jerry


Wed Nov 12, 2008 10:22 pm
Profile E-mail YIM WWW

Joined: Wed Oct 08, 2008 11:27 pm
Posts: 141
Location: UK
Post Re: Adding records to another database?
Hi

I know this is a dumb question but how do I wright a INSERT INTO another table in the same database upon a successful add

_________________
Thanks
Simon
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
dbQwikSite Developer Version: 5.4.0.4
cPanel Version: 11.24.4-S33268
WHM 11.24.2 - X 3.9
Apache version: 2.0.63
PHP version: 5.2.5
MySQL version: 5.0.51a-community
Operating system: Linux


Sun Jan 11, 2009 7:35 am
Profile WWW

Joined: Wed Oct 08, 2008 11:27 pm
Posts: 141
Location: UK
Post Re: Adding records to another database?
this is to add only one of the item from the same add page?

_________________
Thanks
Simon
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
dbQwikSite Developer Version: 5.4.0.4
cPanel Version: 11.24.4-S33268
WHM 11.24.2 - X 3.9
Apache version: 2.0.63
PHP version: 5.2.5
MySQL version: 5.0.51a-community
Operating system: Linux


Sun Jan 11, 2009 7:37 am
Profile WWW

Joined: Fri May 09, 2008 5:38 am
Posts: 271
Location: Texas USA
Post Re: Adding records to another database?
Since you have the DEV versions it is pretty straight forward. Open the project and go to the custom code editor. Under Database select On Add Data Success in the associated box you will need code to access the one field from the 1st table you want to reuse. You can get this value using function
qsrequest such as
$value = qsrequest("req_field_name");
then you can use that $value in a standard MySQL insert statement
$inst = "insert into table2 values ('$value')";
$result = @mysql_query($inst) or die("Your SQL: " . $inst . "<br /> Error: (" . mysql_errno() . ") " . mysql_error());

Dont seem likley that the second table will have only 1 column? Where will the values for the other columns come from? I think you will need to look into Unbound Fields to supply the rest of the data you need.


I know the explaination above seems hard to follow :-) I am much more comfortable writing code than explainations :-) so I have attached a screen shot -- hope this helps


You do not have the required permissions to view the files attached to this post.


Sun Jan 11, 2009 10:45 am
Profile E-mail YIM WWW

Joined: Wed Oct 08, 2008 11:27 pm
Posts: 141
Location: UK
Post Re: Adding records to another database?
Hi

I now this is a old post but i am trying to use this again but I am getting a php line error:

this is what code I am using

Code:
$alogRecordID = "";
$alogDATE = qsrequest("req_Date_Updated");
$alogUSERNAME = $_SESSION["UserLogon"];
$alogDESCRIPTION = "Add Member: "qsrequest("req_First_Name") qsrequest("req_Last_Name");
$alogPAGE = $_SERVER[SCRIPT_NAME];
$inst = "insert into table2 (RecordID, DATE, USERNAME, DESCRIPTION, PAGE)";
$inst .= "values ('$alogRecordID', '$alogDATE', '$alogUSERNAME', '$alogDESCRIPTION', '$alogPAGE')";
$result = @mysql_query($inst) or die("Your SQL: " . $inst . "<br /> Error: (" . mysql_errno() . ") " . mysql_error());


This is the line php has error with:

Code:
$alogDESCRIPTION = "Add Member: "qsrequest("req_First_Name") qsrequest("req_Last_Name");


what am I doing wrong Please?

_________________
Thanks
Simon
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
dbQwikSite Developer Version: 5.4.0.4
cPanel Version: 11.24.4-S33268
WHM 11.24.2 - X 3.9
Apache version: 2.0.63
PHP version: 5.2.5
MySQL version: 5.0.51a-community
Operating system: Linux


Thu Oct 22, 2009 7:38 am
Profile WWW

Joined: Thu May 29, 2008 4:49 pm
Posts: 16
Post Re: Adding records to another database?
Not sure this will help but changing to

$alogDESCRIPTION = "Add Member: qsrequest(req_First_Name) qsrequest(req_Last_Name)";

returns no error in my php IDE.


Sat Oct 24, 2009 10:50 pm
Profile E-mail
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Copyright © 2004-2008 TheDevShop Ltd. All Rights Reserved