Page 1 of 1

A bit of PHP help

Posted: Mon Oct 13, 2008 1:52 pm
by tinamiller1
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... :banghead: :banghead: :banghead:

<?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);


?>

Re: A bit of PHP help

Posted: Mon Oct 13, 2008 1:56 pm
by omniuni
As per your existing solution, you could set a chron job to execute it automatically... perhaps this would work well enough?

Re: A bit of PHP help

Posted: Mon Oct 13, 2008 2:03 pm
by tinamiller1
I have no clue what a chron job is. I am using php in a windows environment using yahoo as the host their merchant solutions so their functions are limited. When I run the code I posted it doesn't update the database so the code is wrong and that is what I need help with. The right code for this.

Re: A bit of PHP help

Posted: Mon Oct 13, 2008 6:52 pm
by califdon
Have you replaced the values for $DB_Server, $DB_Username, $DB_Password and $DB_DBname with the values for your installation? Where is the value for $quantity coming from? Indeed, what you have shown us appears to be just a small fragment of the script necessary to update your local database. You're asking us to guess how your entire system operates.