What I want to achieve is this:
1. auto download excel sheet (done using wget / unzip)
2. import excel sheet into mysql (done using excel2mysql perl script)
3. update the values in the products table, and send an e-mail with the remaining records (new articles, should be inserted in the database later on)
The first two steps run flawlessly, but then it stops. I wrote a command-line php script which doesn't do what it should. Am I doing something impossible? Am I doing it wrong? Is there an easier way?
Here is the php code with comments:
<?PHP
$cn = mysql_connect("localhost", "username", "password")or die ("connection failed"); //connecting to the db
@mysql_select_db("realonecomp_nl",$cn) or die ("No such database"); //select the right database
$sql_tempsmall = mysql_query("SELECT * FROM tempsmall ORDER BY ART_NO",$cn)or die (mysql_error());//get all records in a recordset
while ($rs_tempsmall = mysql_fetch_row($sql_tempsmall) or die (mysql_error())) { // for each record
$temp_id=$rs_tempsmall[ART_NO]; //get the ART_NO value into a string
$sql_oscread = mysql_query("SELECT * FROM products WHERE products_model='$temp_id'",$cn)or die(mysql_error()); // select the row which matches the ART_NO string
$count_oscread = mysql_num_rows($sql_oscread) or die (mysql_error()); //check if there is a record returned
if ($count_oscread>=1) { // there is an record which matches. Update the price
mysql_query("UPDATE products SET products_price='$rs_tempsmall[ART_PRICE]' where products_id='$rs_tempsmall[ART_NO]'",$cn) or die (mysql_error());
} else {
print "new product"; //else print a debug message
$new_prod = "yes";
}
}
if ($new_prod == "yes") {
echo "Found 1 new product."; // another debug message, here comes the code for the mailing later on.
}
mysql_close();
?>
I must note that i'm kinda new to PHP and MySQL, but i do have a lot of experience with ASP and MS-SQL. (We're moving to new servers, that's why i need to switch to php)
--edit--
All currently happens is:
[user@host ecl]# php updat_small.php
X-Powered-By: PHP/4.2.2
Content-type: text/html
(And nothing happens in the mysql table)
not all products are present, so it must give the debug messages.