PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Nov 22, 2014 4:59 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Aug 12, 2007 2:28 pm 
Offline
Forum Commoner

Joined: Sat Jun 24, 2006 8:14 am
Posts: 39
Location: Ontario, Canada
I'm trying to do something that should be so simple.

I want to pass a variable to a php cron job script.
This is the php script:

Syntax: [ Download ] [ Hide ]
#!/usr/bin/php

<?php

require('connect.php');

$id = (int)$_GET['id'];

$game_data = mysql_fetch_array(mysql_query("SELECT game_id FROM game_data WHERE week=id"));

$update = "UPDATE results_data SET status='Closed' WHERE results_id=$game_data[0]";

$update_info = mysql_query($update) or die ('Database Error: ' . mysql_error());

echo "Cron Job ran Successfully";

?>

This works perfectly if put the 'id' in directly and not pass it. However, trying to pass the data gives the 'Input File not found error'. Now, doing some searching I came across a thread that said you can't pass variables in the tradtional sense. eg $_GET So the syntax was to just use a space.

eg. script.php variable1=value

This worked in the fact that I now get a MySQL error because of not reading the 'id' variable.

So how do you read php variables with a space instead of a question mark into the script?

Heres the cron job command line:
Syntax: [ Download ] [ Hide ]
php -q /home/mysite/public_html/cron/update_cron_22.php id=22


Any help appreciated.


Last edited by WorldCom on Sun Aug 12, 2007 3:02 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 12, 2007 2:43 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4294
Location: Sofia, Bulgaria
http://www.phpbuilder.com/columns/darrell20000319.php3?page=2

You don't have to do this like GET (i.e. var=value) - instead:



Syntax: [ Download ] [ Hide ]
php -q /home/mysite/public_html/cron/update_cron_22.php 22


And you'll have in $argv[1] value of 22.

_________________
Image
http://openfmi.net/projects/flattc/ Linux is better :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 12, 2007 3:02 pm 
Offline
Forum Commoner

Joined: Sat Jun 24, 2006 8:14 am
Posts: 39
Location: Ontario, Canada
That's exactly what I was looking for.
Works great thanks :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group