A bit of PHP help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tinamiller1
Forum Newbie
Posts: 2
Joined: Mon Oct 13, 2008 1:49 pm

A bit of PHP help

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


?>
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: A bit of PHP help

Post by omniuni »

As per your existing solution, you could set a chron job to execute it automatically... perhaps this would work well enough?
tinamiller1
Forum Newbie
Posts: 2
Joined: Mon Oct 13, 2008 1:49 pm

Re: A bit of PHP help

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: A bit of PHP help

Post 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.
Post Reply