Page 1 of 1

Cron Errors - URGENT HELP NEEDED!

Posted: Tue Aug 10, 2004 5:49 am
by MasonUK
Okay. I've been using PHP and MySQL for about three weeks now. I have been creating a game called STI ( http://www.TREK.co.nr ).

I need to run a cron but as this being my first time I have made some mistakes somewhere.

Here is my code...

Code: Select all

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

When this script attepts to run I recieve the following message...
/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 really need this script working!! Thanks in advanced for any help you can give. Don't forget that I have not been using PHP/MySQL/Cron for very long, use beginners terms and try to explain everything :D

Posted: Tue Aug 10, 2004 7:24 am
by Grim...
I don't think your CRON is hitting the right page.

You've been using PHP for three weeks and you're trying to write an online multiplayer game?

viewtopic.php?t=23330

Posted: Tue Aug 10, 2004 7:26 am
by Grim...
I'm now sure your CRON is hitting the wrong page.
The first error is:

Code: Select all

/home/trek/public_html/scripts/update_strentgh.php: line 1: ?php 
: No such file or directory
But line 1 of your code is:

Code: Select all

<?php
Check the url.

Posted: Tue Aug 10, 2004 8:42 am
by ldomingues
What are you executing in cron?

I hope it's not: /home/trek/public_html/scripts/update_strentgh.php

1) To run the php script you should use "wget http://localhost/scripts/update_strentgh.php" or replace localhost with your website if you're running virtual hosts.

2) Or run "path_to_php/php /home/trek/public_html/scripts/update_strentgh.php"

Posted: Tue Aug 10, 2004 10:04 am
by feyd
when running through cron, it's like running through cgi, you need to have a shebang on the first line:

Code: Select all

#!/usr/bin/php
or similar...

Posted: Tue Aug 10, 2004 10:05 am
by MasonUK
Hi. I tried that local host URL but I recieve the following error

Code: Select all

/bin/sh: line 1: http://localhost/scripts/update_strentgh.php: No such file or directory


My game is almost complete. All I need to do is get threee cron scripts working. Its nothing incredible, just a text-based game which uses a database. Its based on the TV show Star Trek.

If anyone would like to try it out feel free to signup, the address is http://www.TREK.co.nr.



Does anyone have any other ideas, my webhost is a small UK compnay and the support teams have no idea how to use cron!!!!

Posted: Tue Aug 10, 2004 10:28 am
by ldomingues
Try running it from the command-line:

Code: Select all

wget http://localhost/scripts/update_strentgh.php
If it works, put it in cron.

Reply

Posted: Tue Aug 10, 2004 10:53 am
by MasonUK
Okay. I now recieve the following message...

Code: Select all

--11:48:00--  http://trek.f4u.us/scripts/update_strength.php
           => `update_strength.php.3'
Resolving trek.f4u.us... done.
Connecting to trek.f4u.us&#1111;69.41.245.146]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified &#1111;text/html]

    0K                                                         434.57 KB/s

11:48:00 (434.57 KB/s) - `update_strength.php.3' saved &#1111;445]
Does this mean its worked?

Posted: Tue Aug 10, 2004 10:57 am
by MasonUK
Its worked!!!

Thanks for everyone who has contributed. I can finally finish my game, thanks!

Posted: Tue Aug 10, 2004 12:36 pm
by ldomingues
Put this in cron:

Code: Select all

wget --quiet --spider http://localhost/scripts/update_strentgh.php
So that there's no ouput and the file isn't saved.