Jump to content

Help With a Cron Script


stormx

Recommended Posts

I've been working & built a cron script like the following below, what I can't work out is why it's not updating the database. All I notice is the current readings in the database just vanish.

 

Here is my code:

 

<?php
session_start();

// Connect to the database....
mysql_connect("localhost", "username", "pass") or die("Whoops! We cannot connect to the mysql server!");

// Select the database...
mysql_select_db("db") or die("Whoops! We cannot select the specified database!");

$sql_users = mysql_query("SELECT `id` FROM `users`") or die("Error");

while($id = mysql_fetch_array($sql_users)) {
    $exetelusername = $id['exetelusername'];
$exetelpassword = $id['exetelpassword'];

//get usage 

$link = "https://www.exetel.com.au/members/usagemeter.php?$exetelusername,$exetelpassword";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$str = curl_exec($ch);

$tmp_explode = explode("<br>", $str);

$data = array();

foreach($tmp_explode as $line){
$tmp_line = explode("=", $line);
$data[$tmp_line[0]] = $tmp_line[1];
}

//end it

$onpeakusage = $data['data_down'];

$lastup = date("d\/m\/Y");
mysql_query("UPDATE `user_usage` SET `onpeak` = '$onpeakusage', `user_id` = '$id[id]'") or die("Error");
}
$date = date('l jS \of F Y h:i:s A');
echo '
<center><font face="Comic Sans MS" size="6" color="green"><strong>This cron has succesfully ran!</strong></font><br />This cron run at: <i>'.$date.'</i><br /></center>
'

?>

 

Any help?

Link to comment
https://forums.phpfreaks.com/topic/122077-help-with-a-cron-script/
Share on other sites

First thing i noticed is this part:

 

$sql_users = mysql_query("SELECT `id` FROM `users`") or die("Error");

while($id = mysql_fetch_array($sql_users)) {
    $exetelusername = $id['exetelusername'];
    $exetelpassword = $id['exetelpassword'];

 

You haven't selected the 'exetelusername' and 'exetelpassword' in the query, so those variables aren't getting any values. You have selected only 'id'.

If you wrote this script by yourself, then try debugging it. Check if the variables you're using in the update query get any value. I've never used curl so it's a bit difficult to understand what's going on there. The best bet would be breaking down your script in sections and check where the problem is.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.