Using PHP from the command line

A

Anonymous

Guest
Hey,

First, sorry, posted in Errors before, but I thought that this might be a better place to post in...

This is how it is...
I do add.php?name=something in the browser, and all works as it should (adding the something to mysql database). However, I cant make it work from the command line! According to the php manual site which says:
"To hand over the GET-variables in interactive mode like in HTTP-Mode (e.g. your URI is myprog.html?hugo=bla&bla=hugo), you have to call

php myprog.html '&hugo=bla&bla=hugo'
(two & instead of ? and &!)

There just a little difference in the $ARGC, $ARGV values, but I think this is in those cases not relevant."
it should be: php.exe add.php '&name=something', but its not working! I get the error Error: name not set. name is not a intern commando, extern commando, program or commandofile.) So, it seems that it's not GETTING any value by doing that add.php '&name=something' thingy...

Here is the code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252">
</HEAD>
<BODY>
<?
include('datastore.inc.php');
if (!isset($name)) {
echo "<B>Error: name not set.</B>";
exit;
}
$name = addslashes(trim($name));
$time = time();
$query = "INSERT INTO `names` VALUES ('', '$name', '$time')";
$result = mysql_query($query);
?>
</BODY>
</HTML>

Some that can tell whats wrong?

Thanx,
Ace
 
Ace said:
Hey,

First, sorry, posted in Errors before, but I thought that this might be a better place to post in...

This is how it is...
I do add.php?name=something in the browser, and all works as it should (adding the something to mysql database). However, I cant make it work from the command line! According to the php manual site which says:
"To hand over the GET-variables in interactive mode like in HTTP-Mode (e.g. your URI is myprog.html?hugo=bla&bla=hugo), you have to call

php myprog.html '&hugo=bla&bla=hugo'
(two & instead of ? and &!)

There just a little difference in the $ARGC, $ARGV values, but I think this is in those cases not relevant."
it should be: php.exe add.php '&name=something', but its not working! I get the error Error: name not set. name is not a intern commando, extern commando, program or commandofile.) So, it seems that it's not GETTING any value by doing that add.php '&name=something' thingy...

Here is the code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252">
</HEAD>
<BODY>
<?
include('datastore.inc.php');
if (!isset($name)) {
echo "<B>Error: name not set.</B>";
exit;
}
$name = addslashes(trim($name));
$time = time();
$query = "INSERT INTO `names` VALUES ('', '$name', '$time')";
$result = mysql_query($query);
?>
</BODY>
</HTML>

Some that can tell whats wrong?

Thanx,
Ace



It's very simlpe use in command line double quotes, it's work.
Example: php.exe -f add.php "?name=aaa"

--
Sincerely,
Dmitriy S. Plakhotnik
AlarIT programmer
http://www.AlarIT.com
 
Back
Top