473,385 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with this code - parse insert into Mysql

Can someone help me with this code - I'm trying to retrieve updated
product information by pulling 3 fields and inserting values into my
MYSQL db. In my code below I'm getting the page but I can't get the
date inserted into the DB what am I doing wrong.

Second Can I suppress output to screen. I'm planning on running this
in cron if I'm inserting into db do I have to output to screen
This is the method my host company told me to use. they gave me the
Curl portion of the code which I modified.

Thanks
Steve
<?PHP

#$URL="https://shop.xxxxxxx.com/feeds/productdownload.php?
#fields=sku,qty,price&delim=csv&ohtime=1212278400& invtype=st#ock&id=MPB_MzUxxxxxU4MzQyNzk5";
(Hidden for security #reasons)
#Output looks like this
10001,0,822.51 10002,1,320.86 10003,1,498.91 10004,0,288.77
10005,1,573.91 10006,19,52.50 10007,1,822.51 10008,2,129.89
10010,0,15.63 10011,35,64.50 10012,5,445.65 10013,1,572.99
10014,13,23.53 10015,1,50.00 10016,5,12.99 10017,30,15.60 10018,9,8.24
10019,2,795.46 10020,222,2.40 10021,6,24.38 10024,4,24.38
10025,0,82.50 10026,4,14.38 10027,1,141.25 10030,1,214.12
10036,0,352.02 10043,4,27.50 10046,60,104.51 10047,4,955.37
10054,4,193.80 10122,6,409.50 10123,6,507.50 10127,6,483.00
10141,10,199.50 10147,0,7.50 10149,2,37.10 10156,8,63.75 10157,1,7.64
10158,0,29.83 10167,66,21.73 10169,8,36.47 10171,0,182.06
10177,23,12.00 10178,0,52.50 10179,1,16.50 10183,2,16.00 10195,0,27.00
10207,90,20.17 10245,0,55.29 10278,2,25.60 10284,3,16.98
10288,4,100.00 10333,2,84.99 10341,6,21.08 10342,3,125.31

if (isset($_GET["site"])) { $URL = $_GET["site"]; }
$ch = curl_init();
#"echo "URL = $URL <br>n";
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:
3128");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_URL, $URL);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);

$result = curl_exec ($ch);
# Variables that need to be set by you.
#$file = "https://shop.cwrelectronics.com/feeds/productdownload.php?
fields=sku,qty,price&delim=csv&ohtime=1212278400&i nvtype=stock&id=MPB_MzU4MzQyMzU4MzQyNzk5";
$hostname = "xxxx.secureserver.net";
$username = "xxxxxxx";
$password = "xxxxxx";
$dbname = "xxxxxxxx";
$table = "Inv_Refresh";
$field1 = "Field1";
$field2 = "Field2";
$field3 = "Field3";
$field4 = "Field4";
$field4m = 0.1777;

# No need to change anything here
mysql_connect($hostname,$username,$password);
mysql_select_db($dbname);
$result = str_replace("\r","",$result);
$lines = explode("\n",$result);

foreach ($lines as $line) {
$values = explode(",",$line);
$sql = "REPLACE INTO $table ($field1,$field2,$field3,$field4) VALUES
('$values[0]','$values[1]','$values[2]','".($values[2] *
$field4m)."');";
mysql_query($sql);
}
curl_close ($ch);
?>
Jul 26 '08 #1
4 1797
On Jul 26, 1:02 pm, Steve <dafella...@yahoo.comwrote:
Can someone help me with this code - I'm trying to retrieve updated
product information by pulling 3 fields and inserting values into my
MYSQL db. In my code below I'm getting the page but I can't get the
date inserted into the DB what am I doing wrong.

Second Can I suppress output to screen. I'm planning on running this
in cron if I'm inserting into db do I have to output to screen
This is the method my host company told me to use. they gave me the
Curl portion of the code which I modified.

Thanks
Steve
Yes, I'm sure lots of people can solve the problem - but you need to
take a look at why you're not able to work this out for yourself.

You should read this:

http://www.php.net/errorfunc

then this:

http://www.catb.org/~esr/faqs/smart-questions.html

Then if you're still stuck, apply what you've learnt to a new usenet
post.

C.
Jul 27 '08 #2
Steve wrote:
Can someone help me with this code - I'm trying to retrieve updated
product information by pulling 3 fields and inserting values into my
MYSQL db. In my code below I'm getting the page but I can't get the
date inserted into the DB what am I doing wrong.
"I can't get the date inserted" isn't very clear. What's the SQL
statement you're trying to use? What's the error you get (from MySQL or
PHP)?

Is this even a PHP problem? It looks more like a SQL problem - in which
case you should be asking on comp.databases.mysql.
Second Can I suppress output to screen. I'm planning on running this
in cron if I'm inserting into db do I have to output to screen
This is the method my host company told me to use. they gave me the
Curl portion of the code which I modified.
You never "have" to output anything to the screen.
Thanks
Steve
<?PHP

#$URL="https://shop.xxxxxxx.com/feeds/productdownload.php?
#fields=sku,qty,price&delim=csv&ohtime=1212278400& invtype=st#ock&id=MPB_MzUxxxxxU4MzQyNzk5";
(Hidden for security #reasons)
#Output looks like this
10001,0,822.51 10002,1,320.86 10003,1,498.91 10004,0,288.77
10005,1,573.91 10006,19,52.50 10007,1,822.51 10008,2,129.89
10010,0,15.63 10011,35,64.50 10012,5,445.65 10013,1,572.99
10014,13,23.53 10015,1,50.00 10016,5,12.99 10017,30,15.60 10018,9,8.24
10019,2,795.46 10020,222,2.40 10021,6,24.38 10024,4,24.38
10025,0,82.50 10026,4,14.38 10027,1,141.25 10030,1,214.12
10036,0,352.02 10043,4,27.50 10046,60,104.51 10047,4,955.37
10054,4,193.80 10122,6,409.50 10123,6,507.50 10127,6,483.00
10141,10,199.50 10147,0,7.50 10149,2,37.10 10156,8,63.75 10157,1,7.64
10158,0,29.83 10167,66,21.73 10169,8,36.47 10171,0,182.06
10177,23,12.00 10178,0,52.50 10179,1,16.50 10183,2,16.00 10195,0,27.00
10207,90,20.17 10245,0,55.29 10278,2,25.60 10284,3,16.98
10288,4,100.00 10333,2,84.99 10341,6,21.08 10342,3,125.31

if (isset($_GET["site"])) { $URL = $_GET["site"]; }
$ch = curl_init();
#"echo "URL = $URL <br>n";
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:
3128");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_URL, $URL);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);

$result = curl_exec ($ch);
# Variables that need to be set by you.
#$file = "https://shop.cwrelectronics.com/feeds/productdownload.php?
fields=sku,qty,price&delim=csv&ohtime=1212278400&i nvtype=stock&id=MPB_MzU4MzQyMzU4MzQyNzk5";
$hostname = "xxxx.secureserver.net";
$username = "xxxxxxx";
$password = "xxxxxx";
$dbname = "xxxxxxxx";
$table = "Inv_Refresh";
$field1 = "Field1";
$field2 = "Field2";
$field3 = "Field3";
$field4 = "Field4";
$field4m = 0.1777;

# No need to change anything here
mysql_connect($hostname,$username,$password);
mysql_select_db($dbname);
$result = str_replace("\r","",$result);
$lines = explode("\n",$result);

foreach ($lines as $line) {
$values = explode(",",$line);
$sql = "REPLACE INTO $table ($field1,$field2,$field3,$field4) VALUES
('$values[0]','$values[1]','$values[2]','".($values[2] *
$field4m)."');";
mysql_query($sql);
}
curl_close ($ch);
?>

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jul 27 '08 #3
Steve wrote:
Can someone help me with this code - I'm trying to retrieve updated
product information by pulling 3 fields and inserting values into my
MYSQL db. In my code below I'm getting the page but I can't get the
date inserted into the DB what am I doing wrong.

Second Can I suppress output to screen. I'm planning on running this
in cron if I'm inserting into db do I have to output to screen
This is the method my host company told me to use. they gave me the
Curl portion of the code which I modified.

Thanks
Steve
<?PHP

#$URL="https://shop.xxxxxxx.com/feeds/productdownload.php?
#fields=sku,qty,price&delim=csv&ohtime=1212278400& invtype=st#ock&id=MPB_MzUxxxxxU4MzQyNzk5";
(Hidden for security #reasons)
#Output looks like this
10001,0,822.51 10002,1,320.86 10003,1,498.91 10004,0,288.77
10005,1,573.91 10006,19,52.50 10007,1,822.51 10008,2,129.89
10010,0,15.63 10011,35,64.50 10012,5,445.65 10013,1,572.99
10014,13,23.53 10015,1,50.00 10016,5,12.99 10017,30,15.60 10018,9,8.24
10019,2,795.46 10020,222,2.40 10021,6,24.38 10024,4,24.38
10025,0,82.50 10026,4,14.38 10027,1,141.25 10030,1,214.12
10036,0,352.02 10043,4,27.50 10046,60,104.51 10047,4,955.37
10054,4,193.80 10122,6,409.50 10123,6,507.50 10127,6,483.00
10141,10,199.50 10147,0,7.50 10149,2,37.10 10156,8,63.75 10157,1,7.64
10158,0,29.83 10167,66,21.73 10169,8,36.47 10171,0,182.06
10177,23,12.00 10178,0,52.50 10179,1,16.50 10183,2,16.00 10195,0,27.00
10207,90,20.17 10245,0,55.29 10278,2,25.60 10284,3,16.98
10288,4,100.00 10333,2,84.99 10341,6,21.08 10342,3,125.31

if (isset($_GET["site"])) { $URL = $_GET["site"]; }
$ch = curl_init();
#"echo "URL = $URL <br>n";
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:
3128");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_URL, $URL);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);

$result = curl_exec ($ch);
# Variables that need to be set by you.
#$file = "https://shop.cwrelectronics.com/feeds/productdownload.php?
fields=sku,qty,price&delim=csv&ohtime=1212278400&i nvtype=stock&id=MPB_MzU4MzQyMzU4MzQyNzk5";
$hostname = "xxxx.secureserver.net";
$username = "xxxxxxx";
$password = "xxxxxx";
$dbname = "xxxxxxxx";
$table = "Inv_Refresh";
$field1 = "Field1";
$field2 = "Field2";
$field3 = "Field3";
$field4 = "Field4";
$field4m = 0.1777;

# No need to change anything here
mysql_connect($hostname,$username,$password);
mysql_select_db($dbname);
$result = str_replace("\r","",$result);
$lines = explode("\n",$result);

foreach ($lines as $line) {
$values = explode(",",$line);
$sql = "REPLACE INTO $table ($field1,$field2,$field3,$field4) VALUES
('$values[0]','$values[1]','$values[2]','".($values[2] *
$field4m)."');";
mysql_query($sql);
}
curl_close ($ch);
?>
My suggestion is to break up your code into smaller pieces (processes)
and debug each piece one at a time. Your code is rather hard to follow
in what you're trying to accomplish so with each piece comment the code
with the function (purpose) of the code and the desired result.

Also, you need to explain (in a repost) from what this code is being
invoked (shell/Command-Line, webpage, Windows, Unix, ect...) as it will
react differently in each case. It seems to me from reading your post
that you're invoking this from the command-Line since you are going to
use cron to invoke it.

As hard as the devel team has tried the command-line functionality of
PHP is, in my opinion, not fully finished and leaves me wanting in most
cases when I use it solely as command-line script. As a result of this I
will generally use is as a "shell-out" within ksh or bash. Using the two
in concert with each other (using ksh as the main script and then
shelling-out to php) compliments the others short comings.

One more suggestion, if you can clarify the purpose of the script and
the desired result there maybe a possibility that there is a better
solution to using MySQL. There are better databases out there that
handle command-line applications better than MySQL. SQLite comes to my
mind right away.

Try these suggestions and repost.
Carl
--

Carl Lindgren
C. R. Lindgren Consulting | Business on the Desktop

****
To Reply Remove the (*) from the "reply to"
Jul 28 '08 #4
Steve wrote:
Can someone help me with this code - I'm trying to retrieve updated
product information by pulling 3 fields and inserting values into my
MYSQL db. In my code below I'm getting the page but I can't get the
date inserted into the DB what am I doing wrong.

Second Can I suppress output to screen. I'm planning on running this
in cron if I'm inserting into db do I have to output to screen
This is the method my host company told me to use. they gave me the
Curl portion of the code which I modified.

Thanks
Steve
<?PHP

#$URL="https://shop.xxxxxxx.com/feeds/productdownload.php?
#fields=sku,qty,price&delim=csv&ohtime=1212278400& invtype=st#ock&id=MPB_MzUxxxxxU4MzQyNzk5";
(Hidden for security #reasons)
#Output looks like this
10001,0,822.51 10002,1,320.86 10003,1,498.91 10004,0,288.77
10005,1,573.91 10006,19,52.50 10007,1,822.51 10008,2,129.89
10010,0,15.63 10011,35,64.50 10012,5,445.65 10013,1,572.99
10014,13,23.53 10015,1,50.00 10016,5,12.99 10017,30,15.60 10018,9,8.24
10019,2,795.46 10020,222,2.40 10021,6,24.38 10024,4,24.38
10025,0,82.50 10026,4,14.38 10027,1,141.25 10030,1,214.12
10036,0,352.02 10043,4,27.50 10046,60,104.51 10047,4,955.37
10054,4,193.80 10122,6,409.50 10123,6,507.50 10127,6,483.00
10141,10,199.50 10147,0,7.50 10149,2,37.10 10156,8,63.75 10157,1,7.64
10158,0,29.83 10167,66,21.73 10169,8,36.47 10171,0,182.06
10177,23,12.00 10178,0,52.50 10179,1,16.50 10183,2,16.00 10195,0,27.00
10207,90,20.17 10245,0,55.29 10278,2,25.60 10284,3,16.98
10288,4,100.00 10333,2,84.99 10341,6,21.08 10342,3,125.31

if (isset($_GET["site"])) { $URL = $_GET["site"]; }
$ch = curl_init();
#"echo "URL = $URL <br>n";
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:
3128");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_URL, $URL);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);

$result = curl_exec ($ch);
# Variables that need to be set by you.
#$file = "https://shop.cwrelectronics.com/feeds/productdownload.php?
fields=sku,qty,price&delim=csv&ohtime=1212278400&i nvtype=stock&id=MPB_MzU4MzQyMzU4MzQyNzk5";
$hostname = "xxxx.secureserver.net";
$username = "xxxxxxx";
$password = "xxxxxx";
$dbname = "xxxxxxxx";
$table = "Inv_Refresh";
$field1 = "Field1";
$field2 = "Field2";
$field3 = "Field3";
$field4 = "Field4";
$field4m = 0.1777;

# No need to change anything here
mysql_connect($hostname,$username,$password);
mysql_select_db($dbname);
$result = str_replace("\r","",$result);
$lines = explode("\n",$result);

foreach ($lines as $line) {
$values = explode(",",$line);
$sql = "REPLACE INTO $table ($field1,$field2,$field3,$field4) VALUES
('$values[0]','$values[1]','$values[2]','".($values[2] *
$field4m)."');";
mysql_query($sql);
}
curl_close ($ch);
?>
My suggestion is to break up your code into smaller pieces (processes)
and debug each piece one at a time. Your code is rather hard to follow
in what you're trying to accomplish so with each piece comment the code
with the function (purpose) of the code and the desired result.

Also, you need to explain (in a repost) from what this code is being
invoked (shell/Command-Line, webpage, Windows, Unix, ect...) as it will
react differently in each case. It seems to me from reading your post
that you're invoking this from the command-Line since you are going to
use cron to invoke it.

As hard as the devel team has tried the command-line functionality of
PHP is, in my opinion, not fully finished and leaves me wanting in most
cases when I use it solely as command-line script. As a result of this I
will generally use is as a "shell-out" within ksh or bash. Using the two
in concert with each other (using ksh as the main script and then
shelling-out to php) compliments the others short comings.

One more suggestion, if you can clarify the purpose of the script and
the desired result there maybe a possibility that there is a better
solution to using MySQL. There are better databases out there that
handle command-line applications better than MySQL. SQLite comes to my
mind right away.

Try these suggestions and repost.
Carl
--

Carl Lindgren
C. R. Lindgren Consulting | Business on the Desktop

****
To Reply Remove the (*) from the "reply to"
Jul 28 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: leegold2 | last post by:
// This statement below inserting one field works: // mysql_query("INSERT INTO page (page_url) VALUES (\"$url_field\")"); But I wanted to insert into two fields so I was trying all sorts of...
5
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql,...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
4
by: Chuck Haeberle | last post by:
I have an interesting regular expression challenge for someone more experienced with them than I for a data layer class... I need an expression to search a SQL statement (any type, SELECT INSERT...
0
by: Shaggyh | last post by:
hi im needing help with a program im writing to do subnetting i was on before about it and i got some help. the code below wont work for me and i cant think of why not. i was wondering if anyone...
31
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there...
2
by: Extremest | last post by:
Here is the code I have so far. It connects to a db and grabs headers. It then sorts them into groups and then puts all the complete ones into another table. Problem I am having is that for some...
23
by: casper christensen | last post by:
Hi I run a directory, where programs are listed based on the number of clicks they have recieved. The program with most clicks are placed on top and so on. Now I would like people to be apple to...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.