include file for mysql insert/update - problms
Posted: Fri Jul 28, 2006 1:54 pm
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::
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();
}
?>