Hello,
I currently have a webshop with products that are shipped from a big wholesaler under my name. This wholesaler has a database with all the products in it which also contains the variable "status" which contains information if the product is on stock or not.
I use this code:
<?php require_once('Connections/sosql.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_sosql, $sosql);
$query_Recordset1 = "SELECT * FROM product";
$Recordset1 = mysql_query($query_Recordset1, $sosql) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cron - update voorraadstatus</title>
</head>
<body>
<?php
$login = "#*$!X";
$password = "#*$!X";
// index number for status field
$voorraadIndex = 10;
// index number for product ID
$productidIndex = 0;
$filename =
"http://example.com/retail/prijslijst_excel.php"
."?veldenkiezer=TRUE=&tilde=TRUE&productid=on&verk oopprijs=on"
."&naam=on&omschrijving=on&info=on&inkoopprijs=on& categorie=on"
."&merk=on&voorraad=on&btw=on&gewicht=on"
."&admin_username=".$login
."&admin_password=".$password;
$lines = file($filename);
foreach ($lines as $line) {
$columns = explode('"~"', $line);
$voorraad = mysql_real_escape_string($columns[$voorraadIndex]);
$productid = mysql_real_escape_string($columns[$productidIndex]);
$query = "
SELECT COUNT(*) FROM `testuh`
WHERE id ='{$productid}'
";
$result = mysql_query($query);
$hits = (integer) mysql_result($result, 0, 0);
if ($hits == 1) {
$query = "
UPDATE `testuh` SET `levertijd`='{$voorraad}'
WHERE id ='{$productid}'
";
$update = mysql_query($query);
}
}
?>
This code works fine now. However, I still have a few questions:
1. is it possible to give products that havent matched any of the id numbers of the wholesaler a status code EOL (end of life) so that I do not need to delete deleted items at the wholesaler, but I can just update their status so they cant be ordered anymore?
2. Is there any danger when updating that empty fields are imputted (because of error or something)? This would be very bad because empty "voorraad"/staus fields means the product cant be ordered.
Hope to hear what you guyz think about this.
__________________________________________________ _____________________
apartments in Austin
Glossary of Accounting Software Terms