php-general Digest 14 Apr 2008 06:47:07 -0000 Issue 5403
Topics (messages 272956 through 272963):
Re: Send XML file with curl functions
272956 by: Nathan Nobbe
272959 by: Aaron Axelsen
272960 by: Bojan Tesanovic
Re: Need a simple one time search utility
272957 by: Nathan Nobbe
Re: Importing / Adding Fields Into MySql From A List
272958 by: Wolf
Writing MySQL Update Query with NULL value
272961 by: Bill Guion
272962 by: Chris
Re: Evaluating math without eval()
272963 by: Jason Norwood-Young
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
On Sun, Apr 13, 2008 at 1:07 PM, Aaron Axelsen <[EMAIL PROTECTED]> wrote:
> Option 2 is what I'm trying to do, but the problem is that when curl
> sends the file over the command line, when it's processes via PHP the
> attached file comes over $_FILES.
>
im lost here. in option 2 from Bojan's post there is no attached file.
there is only a variable that happens to store xml. if php is handling the
request on the system hosting $url from said post then the xml data will be
made available in the $_POST array albiet the 'data' index.
ergo, php on said system would look something like this
<?php
$rawRequestXml = $_POST['data'];
try {
$requestXml = new SimpleXmlElement($rawRequestXml);
} catch(Exception $e) {
// do error handling stuff
}
?>
> But, added the postdata obviously doesn't allow it to come over that
> way. Is there any way to use option 2 and transmit the file so it will
> come over under $_FILES?
i dont understand the 'need' to have the request data available in the
$_FILES array; whats wrong w/ $_POST ?
-nathan
--- End Message ---
--- Begin Message ---
The problem is that it is a 3rd party API that I am trying to submit
data to. I have submitted a request to make the necessary changes for
what I'm trying to do.
Nathan Nobbe wrote:
On Sun, Apr 13, 2008 at 1:07 PM, Aaron Axelsen <[EMAIL PROTECTED]> wrote:
Option 2 is what I'm trying to do, but the problem is that when curl
sends the file over the command line, when it's processes via PHP the
attached file comes over $_FILES.
im lost here. in option 2 from Bojan's post there is no attached file.
there is only a variable that happens to store xml. if php is handling the
request on the system hosting $url from said post then the xml data will be
made available in the $_POST array albiet the 'data' index.
ergo, php on said system would look something like this
<?php
$rawRequestXml = $_POST['data'];
try {
$requestXml = new SimpleXmlElement($rawRequestXml);
} catch(Exception $e) {
// do error handling stuff
}
?>
But, added the postdata obviously doesn't allow it to come over that
way. Is there any way to use option 2 and transmit the file so it will
come over under $_FILES?
i dont understand the 'need' to have the request data available in the
$_FILES array; whats wrong w/ $_POST ?
-nathan
--
Aaron Axelsen
[EMAIL PROTECTED]
Great hosting, low prices. Modevia Web Services LLC -- http://www.modevia.com
--- End Message ---
--- Begin Message ---
You should read PHP manual more often it is a bible for us :)
http://www.php.net/curl_setopt there is example on that page how to
upload files.
You need to save data to disk first though, which I guess is not a
big deal to do the job
On Apr 14, 2008, at 2:47 AM, Aaron Axelsen wrote:
The problem is that it is a 3rd party API that I am trying to
submit data to. I have submitted a request to make the necessary
changes for what I'm trying to do.
Nathan Nobbe wrote:
On Sun, Apr 13, 2008 at 1:07 PM, Aaron Axelsen
<[EMAIL PROTECTED]> wrote:
Option 2 is what I'm trying to do, but the problem is that when curl
sends the file over the command line, when it's processes via PHP
the
attached file comes over $_FILES.
im lost here. in option 2 from Bojan's post there is no attached
file.
there is only a variable that happens to store xml. if php is
handling the
request on the system hosting $url from said post then the xml
data will be
made available in the $_POST array albiet the 'data' index.
ergo, php on said system would look something like this
<?php
$rawRequestXml = $_POST['data'];
try {
$requestXml = new SimpleXmlElement($rawRequestXml);
} catch(Exception $e) {
// do error handling stuff
}
?>
But, added the postdata obviously doesn't allow it to come over that
way. Is there any way to use option 2 and transmit the file so
it will
come over under $_FILES?
i dont understand the 'need' to have the request data available
in the
$_FILES array; whats wrong w/ $_POST ?
-nathan
--
Aaron Axelsen
[EMAIL PROTECTED]
Great hosting, low prices. Modevia Web Services LLC -- http://
www.modevia.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Bojan Tesanovic
http://www.carster.us/
--- End Message ---
--- Begin Message ---
On Sat, Apr 12, 2008 at 4:31 PM, Al <[EMAIL PROTECTED]> wrote:
> I know how to script one to do the job; but, I was hoping to save a few
> hours..
here; ill spare you the few hours ;) as it stands this is designed to be
invoked from the cli, but theres a class in here that does all the heavy
lifting. im sure you can easily adapt it to suit your needs, but likely you
can use it out-of-the-box. there are some limitations,
recursive only searches
path / filename of matches not returned
cant pipe to it as in
command | php grep.php args
<?php
if($argv[1] == '--help') {
die(usage());
}
$flags = Grep::PREG_GREP_STD;
$pattern = $argv[1];
$path = $argv[2];
if(isset($argv[3])) {
$flags = $argv[3];
}
echo Grep::simpleFactory($pattern, $path, $flags);
function usage() {
echo
<<<USAGE
php grep.php <pattern> <path> [flags]
simple php implementation of grep
note: this version is recursive only
a flag = 1 will invert the search so that results that do not match will be
returned
USAGE;
}
class Grep {
const PREG_GREP_STD = 0;
const PREG_GREP_INVERT = 1; // <- ganked from quercus ;)
private $matches = array();
private $pattern = null;
private $path = '';
private $flags = '';
public function __construct($pattern, $path, $flags=0) {
$this->pattern = $pattern;
$this->path = $path;
$this->flags = $flags;
$this->search();
}
public static function simpleFactory($pattern, $path, $flags=0) {
return new self($pattern, $path, $flags);
}
public function setPattern($pattern) {
$this->pattern = $pattern;
}
public function setPath($path) {
if(is_dir($path) || is_file($path)) {
$this->path = $path;
}
}
public function setFlags($flags) {
$this->flags = $flags;
}
public function search() {
$rdi = new RecursiveDirectoryIterator($this->path);
foreach(new RecursiveIteratorIterator($rdi,
RecursiveIteratorIterator::SELF_FIRST) as $curFile) {
$this->matches = array_merge($this->matches,
preg_grep("/{$this->pattern}/", file($curFile)));
}
}
public function __toString() {
return implode($this->matches);
}
}
?>
enjoy,
-nathan
--- End Message ---
--- Begin Message ---
revDAVE wrote:
Newbie question!
I have a list of field names from another database (not mysql) - like:
name
phone1
phone2
street
city
state
zip
info
etc.... (a bunch more fields)
Q: Is there a way I can add these to an existing empty/blank table?
I have phpMyAdmin and If there's a way add tables w / php - maybe that would
work also....
If I can just get all the field names in the table as text fields - that
would be ok for now - then I can individually change the field type by hand
w phpMyAdmin...
BTW: What is the best field type for 'average' text (not large 'BLOBS')
like:
1 - Street address - maybe less than 255 characters
2 - Info field - maybe more than 255 characters
- (let's assume that user might want to search on the fields):
-text?
-char?
-TINYTEXT?
-mediumtext?
-varchar?
-longtext?
Q: Is there a url to read about the types?
I'm looking at these now but not quite sure ...
http://dev.mysql.com/doc/refman/5.1/en/char.html
http://dev.mysql.com/doc/refman/5.1/en/blob.html
Dave,
You really want to take you MySQL questions to a MySQL list.
Also, for using PHPMyAdmin, RTFM as it tells you how to use it with your
table.
Wolf
--- End Message ---
--- Begin Message ---
I'm trying to write a MySQL UPDATE query where one or more variables
may be NULL. So, I'm trying something like:
$last_name = $_POST['last_name'];
$first_name = $_POST['first_name'];
$suffix = $_POST['suffix'];
$suffix = empty($suffix) ? NULL : $suffix;
$phone = $_POST['phone'];
$phone_index = $_POST['phone_index'];
$update_query = "UPDATE 'phones'
SET 'last_name' = $last_name, 'first_name' = $first_name,
'suffix' = $suffix, 'phone' = $phone
WHERE 'phone_index' = $phone_index;";
However, when I echo out this query, I get:
UPDATE 'phones' SET 'last_name' = Doe, 'first_name' = John, 'suffix'
= , 'phone' = 123-456-7890 WHERE 'phone_index' = 323;
I think, for this to properly update the record, it should be:
UPDATE 'phones' SET 'last_name' = Doe, 'first_name' = John, 'suffix'
= NULL, 'phone' = 123-456-7890 WHERE 'phone_index' = 323;
What am I doing wrong?
-----===== Bill =====-----
--
Nothing is so bad that it can't get worse.
--- End Message ---
--- Begin Message ---
Bill Guion wrote:
I'm trying to write a MySQL UPDATE query where one or more variables may
be NULL. So, I'm trying something like:
$last_name = $_POST['last_name'];
$first_name = $_POST['first_name'];
$suffix = $_POST['suffix'];
$suffix = empty($suffix) ? NULL : $suffix;
$phone = $_POST['phone'];
$phone_index = $_POST['phone_index'];
$update_query = "UPDATE 'phones'
SET 'last_name' = $last_name, 'first_name' =
$first_name,
'suffix' = $suffix, 'phone' = $phone
WHERE 'phone_index' = $phone_index;";
However, when I echo out this query, I get:
UPDATE 'phones' SET 'last_name' = Doe, 'first_name' = John, 'suffix' = ,
'phone' = 123-456-7890 WHERE 'phone_index' = 323;
I think, for this to properly update the record, it should be:
UPDATE 'phones' SET 'last_name' = Doe, 'first_name' = John, 'suffix' =
NULL, 'phone' = 123-456-7890 WHERE 'phone_index' = 323;
1) You don't need quotes around your field names.
2) You do need quotes around your data, plus you should use
mysql_real_escape_string to stop sql injection attacks:
$phone = mysql_real_escape_string($_POST['phone']);
3) What error do you get once you fix both of those up?
Your query should end up looking like:
$query = "UPDATE phones SET last_name='" .
mysql_real_escape_string($_POST['last_name']) . "', ...
or
$last_name = mysql_real_escape_string($_POST['last_name']);
$first_name = mysql_real_escape_string($_POST['first_name']);
// set a default of NULL
$suffix = "NULL";
if (!empty($_POST['suffix'])) {
// note - you need to add the quotes around the data here
$suffix = "'" . mysql_real_escape_string($_POST['suffix']) . "'";
}
$query = "UPDATE phones set last_name='${last_name}',
first_name='${first_name}' ..., suffix=${suffix}";
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
On Sat, 2008-04-12 at 09:05 -0500, Ray Hauge wrote:
>
> you might be able to leverage a call to expr on a bash sell. Just
> replace the variables you're expecting with preg_replace or some
similar
> function.
>
> http://hacktux.com/bashmath
>
http://sysblogd.wordpress.com/2007/08/26/let-bash-do-the-math-doing-calculations-using-that-bash/
>
> I'm not sure if that's any more secure than eval though.
Good idea Ray. I'm thinking that it might be safer to exec a separate
app - preferably sandboxed. That way it could still be PHP (or anything
else really) but without the headache of compromising the main
application.
J
--- End Message ---