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!
|