PDA

View Full Version : PHP Dual Form Processing


Anthony
02-22-2005, 3:00 PM
I am working on a local animal shelter project that also uses PetFinder. I currently have everything in place so that from a "Control Panel" they can go in and update the status of one of the animals.
Adopted, Transfered, and so forth. From this same area I would like it to also update PetFinder. The problem that keeps holding me is that there is a login to your PetFinder panel as well. So does anybody know how to send a user/pass to one form, wait a sec or two for it to login, then update the next form?

Thanks

Anthony

davidw
02-22-2005, 3:18 PM
I'm not sure if I'm following you all the way, but I'm guessing what you want to do is set up the form to call the database on the current user. Really once a person has logged in, as long as the cookie is current, it should automatically update on the form, provided it is being called from the database.

Anthony
02-22-2005, 3:39 PM
Sorry after rereading it three times my own question is confusing. Backing up, What I am trying to do is from a form, when I hit submit it does all the local work (update db, change pages, send email) and also I want it to login to PetFinder, then once it is loged in update that information, So one form processing local then/sametime updating another completely different servers information, however that information is password protected. So it would have to send the user/pass then pause? wait for it to login and then continue sending the info.
So one form updating two db's however second db is password protected on a different server, so has to send u/p first.


Thanks

Anthony

davidw
02-22-2005, 4:20 PM
What databases are you using? MySQL?

Anthony
02-22-2005, 4:41 PM
Yeap MySQL at least on my end, I don't know on PetFinder. However the db is not the issue or question, I am looking if there is a way that PHP can pause or wait if you will while a first set of commands run. Example I think of what I am trying to do..


if (is_array($response))
{
if (count($response) > 0)
{
// Change the array key indexing from 0-base to 1-base
$temp_response = "," . $response[0];
$response_array = explode(",", $temp_response);
unset($response_array[0]);

if ($response_array[1] == 1)
{
$authorized = true;
}
else
{
$error = "<b>" . $response_array[4] . "</b> ";
}
// Debugging Text
if ($test_mode)
{ //set above in step [1]
while (list ($key, $val) = each($response_array))
{
print("<b>$key</b> = " . $val . "<br>\n");
}
}
}
else
{
$authorized = false;
}
}
else
{
$authorized = false;
}


if($authorized)
{
Continue and instert into DB.....
}





I think this is what I want to do..

Thanks,

Anthony

davidw
02-22-2005, 4:55 PM
I believe you can do this, but you'll want to put something in there like this (to differentiate the databases..

function connectDB($db) {
global $host, $database, $username, $password;
switch($db) {
case ("database1"):
$conn_string = "host=" . $host . " dbname=" . $database . " user=" . $username . " password=" . password;
$dbconn = pg_connect($conn_string) or die ("Error Connecting to PostgreSQL DB");
return $dbconn;
break;
case ("database2"):
$dbconn = mysql_connect($host, $username, $password) or die ("Error Connecting to MySQL DB");
return $dbconn;
break;
default;
echo "<P>Invalid Database: $db";
return 0;
}
}

function selectDB($db) {
global $database;
switch($db) {
case ("database1"):
return 1;
break;
case ("database2"):
mysql_select_db($database) or die ("Error Connecting to MySQL DB");
return 1;
break;
default;
echo "<P>Invalid Database: $db";
return 0;
}
}

function queryDB($db, $query) {
switch($db) {
case ("database1"):
if(!$result = @pg_exec($query)){
$result = 0;
}
break;
case ("database2"):
if(!$result = @mysql_query($query)){
$result = 0;
}
break;
default;
echo "<P>Invalid Database: $db";
$result = 0;
}
return $result;
}

Anthony
02-22-2005, 7:06 PM
Well I will keep working on it, maybe after looking at the code yet again :-) To me the big one is the if_authorized...

Thank you,

Anthony

davidw
02-22-2005, 8:18 PM
Basicially if you call both databases and keep the variables separate, it should work - and without a pause. But, if you want a pause, I'm sure something could be put in for that, but as long as the db's are running, it will be within a second or two, depending on location, bandwidth, etc.