Page 1 of 1

include file for mysql insert/update - problms

Posted: Fri Jul 28, 2006 1:54 pm
by tvs008
I can't connect to a mysql db on remote host from our network. The way our network is configured (firewall?) won't allow it. This will not change, so that's not the problem I'm here to addess. As a workaround, I am trying to pass variables to an include file on another machine and that include hits the db successfully as localhost(it connected at least in tests). However, I don't seem to be able to pass variables to this include file for the sql statements. Is this possible to do? am I making a mistake in my process here, not simply code? It would go something like this- pass variable to sql statement in include file, the include then runs sql, then include reports back success or not.

this is my include file::

Code: Select all

<?php
$mydb=mysql_connect("localhost", "xxx", "xxx");
mysql_select_db("xxx", $mydb); 

$sql2="SELECT * FROM _products WHERE ILCProductID = '$ILCProductID'";
$result2 = mysql_query($sql2);
echo mysql_error();

if (mysql_num_rows($result2) == 0) { 
$sql3="INSERT INTO _products (ILCProductID, Title, Authors, ISBN, ILCRetailPrice, CompanyName, ProductType, MediaType, ShipWeight, InInventory, OldilcID) VALUES ('$ILCProductID', '$Title', '$Authors', '$ISBN', '$ILCRetailPrice', '$CompanyName', '$ProductType', '$MediaType', '$ShipWeight', '$InInventory', '$OldIlcID')";
$result3 = mysql_query($sql3);
echo mysql_error();
}
else {
// update rows with existing rows
$sql4="UPDATE _products SET Title = '$Title', Authors = '$Authors', ISBN = '$ISBN', ILCRetailPrice = '$ILCRetailPrice', CompanyName = '$CompanyName', ProductType = '$ProductType', MediaType = '$MediaType', ShipWeight = '$ShipWeight', InInventory = '$InInventory', OldIlcID = '$OldIlcID' WHERE ILCProductID = '$ILCProductID'";
$result4 = mysql_query($sql4);
echo mysql_error();
}
?>

Posted: Fri Jul 28, 2006 2:04 pm
by RobertGonzalez
Clarify this process a little bit, can you? You have one machine that you want to connect your remote database. And you are saying that your network won't allow it. Are you sure this is the case?

Now you say you have another machine that can connect to the database. And you are trying to send variables to that page to pass to the database, am I correct? If so, how can you connect to the remote web server but not the remote database server? And how are you passing these vars to the remote web server?

Posted: Fri Jul 28, 2006 2:17 pm
by tvs008
I am running this sript from our subnetted intranet- the database I'm trying to send info to is located on our host's machine, somewhere else. Originally I ran mysql_connect('host_address','user','pass') but I was getting an authentication error. I think it was because of the subnetted IP I was from.
So, as a workaround, I thought I could put the script that connects and updates/inserts on the host machine to connect as localhost- I tested this as an include file from our intranet to see if it successfully connected and it did.
Now I'm trying to feed the include some variables for the sql statement, but its not working. Can I send variables to an include file?

Posted: Fri Jul 28, 2006 8:29 pm
by RobertGonzalez
Yeah, you can, but I am wondering how you are going to trigger the posting of the other script. If you are trying to pass something from the subnetted server, it would have to post to the hosted server or the hosted server will never process. I think. Does that make sense to you? What I think you need to do is run a script on the hosted server that grabs what you want from the subnetted server.

I am still trying to figure out how your IP address is affecting your ability to hit the database. I didn't know the database could see/care about where the credentials were coming from as long as the credentials authenticated.