Help restructure code run when set with cronjob

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
popuskin
Forum Newbie
Posts: 6
Joined: Thu Sep 04, 2008 8:01 am

Help restructure code run when set with cronjob

Post by popuskin »

The file I wish to run resides on the server xxx.com/test.cvs

I want to set a cron job to run the script below every day.

<?php




include "connect.php";
if(isset($_POST['submit']))
{
$filename=$_POST['filename'];
$handle = fopen("$filename", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{

$import="INSERT into prices values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]')";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";

}
else
{

print "<form action='csv.php' method='post'>";
print "Type file name to import:<br>";
print "<input type='text' name='filename' size='20'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}

?>


Please someone help me restructure it cos cron job can not press the submit button.

Thx all
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help restructure code run when set with cronjob

Post by requinix »

So you want to go from "do something but only if the user hit the button" to "do something".
Which basically means you get rid of the logic that checks for the button and prints the form if it doesn't exist.

This isn't that hard to do if you know some minimal amount of PHP.
Post Reply