Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Cron Help - URGENTLY REQUIRED!!!
Old 08-10-2004, 07:57 AM Cron Help - URGENTLY REQUIRED!!!
Junior Talker

Posts: 1
Trades: 0
I need some help using crons. I need a script to connect to a mysql database and take a field called total_attack from a table called weapons and insert it into a table called rank (in a field called strength). It need to do this for several users every hour (at --:58)

The following is my code:

Code:
<?php

// connect to database

$DBusername=trek;
$DBpassword=*******;
$database=trek_sti;

mysql_connect('localhost',$DBusername,$DBpassword);
mysql_select_db($database) or die( "Unable to access database. Please try again. ERROR: Armory 0");


$sql2 = "select * from user_info" or die("Could not get user info");
$rs2 = mysql_query($sql2);

while ($row2 = mysql_fetch_array($rs2))
{

$username = $row2['username'] or die("Could not get username from array");




$attack1 = MYSQL_QUERY("SELECT * from weapons WHERE username='$username'")
  or die ("An error occured while loading your data. Error: Engineering2");

$attack2 = mysql_fetch_array($attack1) or die ("An error occured while loading your data. Error: Engineering 3");

$attack = $attack2['total_attack'];

?> <P> <?php

echo "$attack";

?> <BR> <?php

echo "$username";

$strength = $attack;

$update = MYSQL_QUERY("UPDATE rank SET strength = $strength WHERE username='$username'") or die("Could not update database");

}

?>
I have managed to make the cron system find the script and attept to run it at the correct time, when it sends my the email informing me of the results from the script I recieve the following


Code:
/home/trek/public_html/scripts/update_strentgh.php: line 1: ?php
: No such file or directory
/home/trek/public_html/scripts/update_strentgh.php: line 2: 
: command not found
/home/trek/public_html/scripts/update_strentgh.php: line 3: //: is a directory
/home/trek/public_html/scripts/update_strentgh.php: line 4: 
: command not found
/home/trek/public_html/scripts/update_strentgh.php: line 5: =trek: command not found
/home/trek/public_html/scripts/update_strentgh.php: line 5: 
: command not found
/home/trek/public_html/scripts/update_strentgh.php: line 6: =yardleys: command not found
/home/trek/public_html/scripts/update_strentgh.php: line 6: 
: command not found
/home/trek/public_html/scripts/update_strentgh.php: line 7: =trek_sti: command not found
/home/trek/public_html/scripts/update_strentgh.php: line 7: 
: command not found
/home/trek/public_html/scripts/update_strentgh.php: line 8: 
: command not found
/home/trek/public_html/scripts/update_strentgh.php: line 9: syntax error near unexpected token `'localhost',$DBusername,$DBpassword'
/home/trek/public_html/scripts/update_strentgh.php: line 9: `mysql_connect('localhost',$DBusername,$DBpassword);
'
Any ideas? I need to get this working for a game I'm making called Star Trek: Interactive...

Please use begineers terms. I have only been using PHP/MySQL/Cron for a few weeks!
MasonUK is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-10-2004, 10:50 AM PHP is ok but
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
You would be better of writing this in say PERL

Still if you insist on PHP you might want to try running the script through php if it does not allready do so.

Just calling the script will leave it confused as it does not know what to parse it with.

secondly run crontab -e

insert this line

59 * * * * <path to php> <path to php script>

59 is the minute you want to run it. In this case it will run evry 59 mins.

That should fix it though i would not personally do it in PHP. Nice one for using a *NIX OS makes a change from the humdrum windows fans..

Ibbo
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Reply     « Reply to Cron Help - URGENTLY REQUIRED!!!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09770 seconds with 12 queries