stormx Posted August 31, 2008 Share Posted August 31, 2008 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 More sharing options...
Fadion Posted August 31, 2008 Share Posted August 31, 2008 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'. Link to comment https://forums.phpfreaks.com/topic/122077-help-with-a-cron-script/#findComment-630248 Share on other sites More sharing options...
stormx Posted August 31, 2008 Author Share Posted August 31, 2008 What would be the appropriate fix for that? Sorry I'm really new to this stuff.. Link to comment https://forums.phpfreaks.com/topic/122077-help-with-a-cron-script/#findComment-630251 Share on other sites More sharing options...
Fadion Posted August 31, 2008 Share Posted August 31, 2008 $sql_users = mysql_query("SELECT id, exetelusername, exetelpassword FROM users") or die("Error"); Maybe you need other fields selected, so just add them after the SELECT statement separated with comma from the other fields. Link to comment https://forums.phpfreaks.com/topic/122077-help-with-a-cron-script/#findComment-630253 Share on other sites More sharing options...
stormx Posted August 31, 2008 Author Share Posted August 31, 2008 Hmm, it still fails.. I just can't understand whats wrong. Link to comment https://forums.phpfreaks.com/topic/122077-help-with-a-cron-script/#findComment-630274 Share on other sites More sharing options...
Fadion Posted August 31, 2008 Share Posted August 31, 2008 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. Link to comment https://forums.phpfreaks.com/topic/122077-help-with-a-cron-script/#findComment-630287 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.