A bit of PHP help
Posted: Mon Oct 13, 2008 1:52 pm
I need some help if anyone can help me with this. I need to have a sql query that reads from two tables that have different info in them. 1 is the datecreation and the other is the quantity, itemnumber and name. then once it gets that I want it to update based on the datecreated and quantity the inventory table. I have a paypal script that auto writes to my 2 tables but couldn't ever figure out how to input an update of the inventory when the customer buys. so i just created a script the user has to run everyday to update inventory. i have been working on this since mid july and done so many diff things and this is like my final crack at this. please please someone out there help me...
<?php
//DB connect creds
$DB_Server = "mysql"; //your MySQL Server
$DB_Username = "username"; //your MySQL User Name
$DB_Password = "userpassword"; //your MySQL Password
$DB_DBName = "mydatabase"; //your MySQL Database Name
//$quantity = paypal_cart_info.$quantity;
//create MySQL connection
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
//inventory handling
$result=mysql_query("SELECT paypal_payment_info.datecreation, paypal_cart_info.itemname, paypal_cart_info.itemnumber, paypal_cart_info.quantity
FROM paypal_payment_info INNER JOIN paypal_cart_info ON paypal_payment_info.txnid = paypal_cart_info.txnid
WHERE (((paypal_payment_info.datecreation)=Date())));
$strquery = sprintf("UPDATE Inventory SET 'numinstock' = numinstock - ",
$quantity . " WHERE Itemnumber = " . $Itemnumber);
mysql_query($strquery);
?>
<?php
//DB connect creds
$DB_Server = "mysql"; //your MySQL Server
$DB_Username = "username"; //your MySQL User Name
$DB_Password = "userpassword"; //your MySQL Password
$DB_DBName = "mydatabase"; //your MySQL Database Name
//$quantity = paypal_cart_info.$quantity;
//create MySQL connection
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
//inventory handling
$result=mysql_query("SELECT paypal_payment_info.datecreation, paypal_cart_info.itemname, paypal_cart_info.itemnumber, paypal_cart_info.quantity
FROM paypal_payment_info INNER JOIN paypal_cart_info ON paypal_payment_info.txnid = paypal_cart_info.txnid
WHERE (((paypal_payment_info.datecreation)=Date())));
$strquery = sprintf("UPDATE Inventory SET 'numinstock' = numinstock - ",
$quantity . " WHERE Itemnumber = " . $Itemnumber);
mysql_query($strquery);
?>