[PHP] PHP-driven alternative to Crystal Report

2010-11-26 Thread AmirBehzad Eslami
Dear List,

I'm looking for an open-source database reporting tool, which is written in
PHP.
Do you know of any php-driven alternative to Crystal Report?
What do you recommend?

Please let me know.
Thank you very much.

-behzad


[PHP] MySQL database export to Excel

2010-11-26 Thread Sotiris Katsaniotis

Greetings fellow PHP developers!

I am looking of a relatively simple way to export a whole database into 
an Excel file. I have several methods to export tables to Excel files 
but unfortunately I have failed to export a whole database!


Can someone be so kind to point me in the right direction?

Thanks a lot!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] MySQL database export to Excel

2010-11-26 Thread Steve Staples
On Fri, 2010-11-26 at 15:21 +0200, Sotiris Katsaniotis wrote:
> Greetings fellow PHP developers!
> 
> I am looking of a relatively simple way to export a whole database into 
> an Excel file. I have several methods to export tables to Excel files 
> but unfortunately I have failed to export a whole database!
> 
> Can someone be so kind to point me in the right direction?
> 
> Thanks a lot!
> 
DISCLAIMER
  This is untested, and just off the top of my pointy head, do some
research, and know how much strain this COULD put on your system.
/DISCLAIMER

there are MANY MySQL commands that you can use, and combine them into 1
script, and then export them into excel, using multiple pages with
something like this:

http://www.codediesel.com/php/creating-excel-documents-in-php/

example mysql queries:
SHOW DATABASES; -- gets a lits of all the databases (skip MySQL and
information_schema)

SHOW TABLES FROM {tablename};  -- gets all the tables in a specific
database


SELECT column_name FROM information_schema.columns WHERE
table_name='{tablename}' AND table_schema='{databasename}'; -- gets you
a list of all the column headers (there are other ways you can avoid
doing this, but this works)


SELECT * FROM {databasename}.{tablename}; -- gets all the rows from a
table in the database


if you were to create a script, and providing your scipt has enough
"max_execution_time", and "memory_limit" (should prolly be done from the
CLI)  you can prolly get it done... 

and yeah, this is a pointer to how it *COULD* be done, but it's not the
only way, nor is it prolly the best either.

Good Luck, and if you need more MySQL related questions answered, try
the my...@lists.mysql.com mailing list.  they are really good over
there.


Steve



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Fw: Spoofing user_agent

2010-11-26 Thread Richard Quadling
Please don't top post.

On 25 November 2010 15:38, Ron Piggott  wrote:
>
> Is "User Agent" suppose to have a hyphen  "-"  ?   Ron
>
>
>
> The Verse of the Day
> “Encouragement from God’s Word”
> http://www.TheVerseOfTheDay.info
> -Original Message- From: Richard Quadling
> Sent: Thursday, November 25, 2010 9:16 AM
> To: Deva
> Cc: Shreyas Agasthya ; Ron Piggott ; php-general@lists.php.net ;
> a...@ashleysheridan.co.uk
> Subject: Re: [PHP] Fw: Spoofing user_agent
>
> On 25 November 2010 11:32, Deva  wrote:
>>
>> Use curl
>> http://php.net/manual/en/book.curl.php
>>
>>
>> On Thu, Nov 25, 2010 at 4:41 PM, Shreyas Agasthya
>> wrote:
>>
>>> I feel you should use more of the 4th method here as you are not trying
>>> to
>>> read the file but the header level  (7th layer) information of the HTTP
>>> protocol.
>>>
>>> http://php.net/manual/en/function.file-get-contents.php
>>>
>>>
>>> --Shreyas
>>>
>>> On Thu, Nov 25, 2010 at 4:11 PM, Ron Piggott <
>>> ron.pigg...@actsministries.org
>>> > wrote:
>>>
>>> >   Will the header pass with using file_get_contents , or should I be
>>> using
>>> > another command, and if so, which one?  Ron
>>> >
>>> > >> >
>>> >     header('User Agent: RonBot (http://www.example.com)');
>>> >     $url = "http://www.example.com";; 
>>> >
>>> >         $input = file_get_contents($url);
>>> >
>>> >
>>> >
>>> > The Verse of the Day
>>> > “Encouragement from God’s Word”
>>> > http://www.TheVerseOfTheDay.info
>>> >
>>> >  *From:* Shreyas Agasthya 
>>> > *Sent:* Thursday, November 25, 2010 4:21 AM
>>> > *To:* Ron Piggott 
>>> > *Cc:* php-general@lists.php.net ; a...@ashleysheridan.co.uk
>>> > *Subject:* Re: [PHP] Fw: Spoofing user_agent
>>> >
>>> > A standard HTTP Request headers is : User Agent (without the >
>>> > underscore).
>>> >
>>> > --Shreyas
>>> >
>>> > On Thu, Nov 25, 2010 at 2:36 PM, Ron Piggott <
>>> > ron.pigg...@actsministries.org> wrote:
>>> >
>>> >>
>>> >> Is this what you are telling me to do:
>>> >>
>>> >> header('user_agent: RonBot (http://www.theverseoftheday.info)');
>>> >>
>>> >> Ron
>>> >>
>>> >> The Verse of the Day
>>> >> “Encouragement from God’s Word”
>>> >> http://www.TheVerseOfTheDay.info
>>> >>
>>> >> From: a...@ashleysheridan.co.uk
>>> >> Sent: Thursday, November 25, 2010 3:34 AM
>>> >> To: Ron Piggott ; php-general@lists.php.net
>>> >> Subject: Re: [PHP] Fw: Spoofing user_agent
>>> >>
>>> >> You need to set it in the header request you make. Putting it in the
>>> >> script you're using as a spider with ini_set won't do anything because
>>> the
>>> >> Target site doesn't know anything about it.
>>> >>
>>> >> Thanks,
>>> >> Ash
>>> >> http://www.ashleysheridan.co.uk
>>> >>
>>> >> - Reply message -
>>> >> From: "Ron Piggott" 
>>> >> Date: Thu, Nov 25, 2010 08:25
>>> >> Subject: [PHP] Fw: Spoofing user_agent
>>> >> To: 
>>> >>
>>> >> I have wrote a script to generate a sitemap of my web site.  It crawls
>>> all
>>> >> of the site web pages.  (About 30,000)
>>> >>
>>> >> I need help to spoof the user_agent variable so the stats program
>>> running
>>> >> in the background ( “AWSTATS” ) will treat the crawl as a bot, not
>>> browsing
>>> >> usage.
>>> >>
>>> >> The sitemap generator is a cron job.  I tried the syntax:
>>> >> ini_set('user_agent', 'RonBot (http://www.theverseoftheday.info)/'/);
>>> >>
>>> >> This didn’t work.  The browsing was attributed to the dedicated IP
>>> >> address.
>>> >>
>>> >> How do I get AWSTATS to access this, such as other entries under the
>>> >> “Robots/Spiders visitors” heading:
>>> >> Unknown robot (identified by 'bot*')
>>> >>
>>> >> I don’t mean any ill will by changing this setting.  Thanks for the
>>> help.
>>> >>
>>> >> Ron
>>> >>
>>> >> The Verse of the Day
>>> >> “Encouragement from God’s Word”
>>> >> http://www.TheVerseOfTheDay.info
>>> >>
>>> >>
>>> >
>>> >
>>> > --
>>> > Regards,
>>> > Shreyas Agasthya
>>> >
>>>
>>>
>>>
>>> --
>>> Regards,
>>> Shreyas Agasthya
>>>
>>
>>
>>
>> --
>> :DJ
>>
>
> It is no use using header(). This sets a header for the client, not
> the server of any file_get_contents() requests.
>
> I use stream_contexts.
>
> $s_Contents = file_get_contents(
>  $s_URL,
>  False,
>  stream_context_create(
>   array(
>     'http' => array(
>       'method' => 'GET',
>       'header' => "User-Agent: RonBot (http://www.example.com)\r\n"
>     ),
>   )
>  )
> );
>
> You can supply cookies, or anything else, with the request. Make sure
> you add a \r\n to each of the headers and just concatenate them.
>
> If you are doing this in a loop, then I'd recommend creating a default
> stream context and then the request would just be ...
>
> $s_Contents = file_get_contents($s_URL);
>
> As the default stream context would be applied.
>
> I had to use a default stream context to route all http requests
> through an NTLM authentication proxy server because PHP doesn't deal
> with NTLM authentication.
>
> See my user notes on
> http://docs.php.net/manual/en/function.stream-context-get-defa

Re: [PHP] Fw: Spoofing user_agent

2010-11-26 Thread Richard Quadling
> On 25 November 2010 15:38, Ron Piggott  wrote:
>>
>> Is "User Agent" suppose to have a hyphen  "-"  ?   Ron
> http://en.wikipedia.org/wiki/User_agent "... the identity is
> transmitted via the User-Agent request header, ... "

http://tools.ietf.org/html/rfc1945#section-10.15

   User-Agent = "User-Agent" ":" 1*( product | comment )

   Example:

   User-Agent: CERN-LineMode/2.15 libwww/2.17b3


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Possible issue in mail() function?

2010-11-26 Thread Richard Quadling
On 25 November 2010 21:30, Tom Hendrikx  wrote:
> Hi,
>
> I noticed that the mail() function in php 5.3.3 on gentoo linux triggers
> a warning when used. A simple debug script with the contents:
>
>  // recipient, subject, body
> mail("s...@example.com", "mail() test", "This is a test");
> ?>
>
> does send mail, but it also raises a warning:
>
> Warning: mail(1): failed to open stream: Permission denied in
> /var/www/www.example.com/htdocs/test-mail/index.php on line 5
>
> After some googling [1] and fiddling with permissions, the message
> disappears when php has write permissions to the file
> /var/www/www.example.com/htdocs/test-mail/1 , in which it writes the
> following data:
>
> ==8<==
> mail() on [/var/www/www.example.com/htdocs/test-mail/index.php:5]: To:
> s...@example.com -- Headers:
> ==8<==
>
> Is this some debug output that someone forgot to remove?
>
> When relevant, the sendmail_path used is "/usr/sbin/sendmail -t -i",
> which is a regular Postfix sendmail.
>
> [1] http://stackoverflow.com/questions/1906403
>
> --
> Kind regards,
>        Tom Hendrikx

Are you logging your emails via the ini setting mail.log? Maybe this
is the issue.


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match fails to resolve variable as a subject

2010-11-26 Thread Richard Quadling
On 26 November 2010 00:07, Da Rock  wrote:
> preg_match("/(\d{1,3})(\.)$/", exec($mixer . ' ' . $command), &$matches)

Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Possible issue in mail() function?

2010-11-26 Thread Tom Hendrikx
On 26/11/10 15:54, Richard Quadling wrote:
> On 25 November 2010 21:30, Tom Hendrikx  wrote:
>> Hi,
>>
>> I noticed that the mail() function in php 5.3.3 on gentoo linux triggers
>> a warning when used. A simple debug script with the contents:
>>
>> > // recipient, subject, body
>> mail("s...@example.com", "mail() test", "This is a test");
>> ?>
>>
>> does send mail, but it also raises a warning:
>>
>> Warning: mail(1): failed to open stream: Permission denied in
>> /var/www/www.example.com/htdocs/test-mail/index.php on line 5
>>
>> After some googling [1] and fiddling with permissions, the message
>> disappears when php has write permissions to the file
>> /var/www/www.example.com/htdocs/test-mail/1 , in which it writes the
>> following data:
> 
> Are you logging your emails via the ini setting mail.log? Maybe this
> is the issue.
> 

Erh, actually, yes I am. Documentation of the setting is rather sparse,
but I enabled it some time ago, expecting it to send the data to the
logging facility (syslog in my case), after which I forgot to check if
that actually happens. The current implementation is rather useless (to
me), so I turned it off again.

Thanks for the tip, but I think that this is actually a bug? Current way
of logging is not very useful, since the file '1' is overwritten (in
stead of appended to) with new data at every run of the mail() function.

--
Regards,
Tom



signature.asc
Description: OpenPGP digital signature


Re: [PHP] Possible issue in mail() function?

2010-11-26 Thread Tom Hendrikx
On 26/11/10 15:54, Richard Quadling wrote:
> On 25 November 2010 21:30, Tom Hendrikx  wrote:
>> Hi,
>>
>> I noticed that the mail() function in php 5.3.3 on gentoo linux triggers
>> a warning when used. A simple debug script with the contents:
>>
>> > // recipient, subject, body
>> mail("s...@example.com", "mail() test", "This is a test");
>> ?>
>>
>> does send mail, but it also raises a warning:
>>
>> Warning: mail(1): failed to open stream: Permission denied in
>> /var/www/www.example.com/htdocs/test-mail/index.php on line 5
>>
>> After some googling [1] and fiddling with permissions, the message
>> disappears when php has write permissions to the file
>> /var/www/www.example.com/htdocs/test-mail/1 , in which it writes the
>> following data:
>>
>> ==8<==
>> mail() on [/var/www/www.example.com/htdocs/test-mail/index.php:5]: To:
>> s...@example.com -- Headers:
>> ==8<==
>>
>> Is this some debug output that someone forgot to remove?
>>
>> When relevant, the sendmail_path used is "/usr/sbin/sendmail -t -i",
>> which is a regular Postfix sendmail.
>>
>> [1] http://stackoverflow.com/questions/1906403
>>
>> --
>> Kind regards,
>>Tom Hendrikx
> 
> Are you logging your emails via the ini setting mail.log? Maybe this
> is the issue.
> 
> 

Erh, actually, yes I am. Documentation of the setting is rather sparse,
but I enabled it some time ago, expecting it to send the data to the
logging facility (syslog in my case), after which I forgot to check if
that actually happens. The current implementation is rather useless (to
me), so I turned it off again.

Thanks for the tip, but I think that this is actually a bug? Current way
of logging is not very useful, since the file '1' is overwritten (in
stead of appended to) with new data at every run of the mail() function.

--
Regards,
Tom



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Possible issue in mail() function?

2010-11-26 Thread Richard Quadling
On 26 November 2010 15:12, Tom Hendrikx  wrote:
> On 26/11/10 15:54, Richard Quadling wrote:
>> On 25 November 2010 21:30, Tom Hendrikx  wrote:
>>> Hi,
>>>
>>> I noticed that the mail() function in php 5.3.3 on gentoo linux triggers
>>> a warning when used. A simple debug script with the contents:
>>>
>>> >> // recipient, subject, body
>>> mail("s...@example.com", "mail() test", "This is a test");
>>> ?>
>>>
>>> does send mail, but it also raises a warning:
>>>
>>> Warning: mail(1): failed to open stream: Permission denied in
>>> /var/www/www.example.com/htdocs/test-mail/index.php on line 5
>>>
>>> After some googling [1] and fiddling with permissions, the message
>>> disappears when php has write permissions to the file
>>> /var/www/www.example.com/htdocs/test-mail/1 , in which it writes the
>>> following data:
>>
>> Are you logging your emails via the ini setting mail.log? Maybe this
>> is the issue.
>>
>
> Erh, actually, yes I am. Documentation of the setting is rather sparse,
> but I enabled it some time ago, expecting it to send the data to the
> logging facility (syslog in my case), after which I forgot to check if
> that actually happens. The current implementation is rather useless (to
> me), so I turned it off again.
>
> Thanks for the tip, but I think that this is actually a bug? Current way
> of logging is not very useful, since the file '1' is overwritten (in
> stead of appended to) with new data at every run of the mail() function.
>
> --
> Regards,
>        Tom
>
>

I'm on windows and my mail.log shows me all the mail I've sent using
the mail() command since I turned it on.

But according to
http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/standard/mail.c?view=markup#l227,
the mail.log file is opened in append mode.

I'm guessing PHP isn't responsible here.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match fails to resolve variable as a subject

2010-11-26 Thread Tamara Temple


On Nov 25, 2010, at 6:07 PM, Da Rock wrote:
preg_match("/(\d{1,3})(\.)$/", exec($mixer . ' ' . $command), & 
$matches)


it looks like you're failing to account for the newline that comes  
back in a command execution. Add trim() around the exec() call and try  
again.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] code quest

2010-11-26 Thread Kirk Bailey
Hello all, my name is Kirk Bailey, and I am new to php, so please be 
forbearing. I code in python, and am trying to learn this language as 
our new client runs a web business based in it.


I need a routine that will return a list of every directory immediately 
under the current directory- but nothing else, just a list of 
directories, 1 level deep, NO FILES, no listing of current dir or prior 
dir either.


Now in python, I would use os.walk, and use the list of dirs and throw 
the other 2 lists away, but this ain't Kansas anymore. Does php even DO 
lists?


Um, a list is a 1 dimenional array, if have a list ALIST and you plug in 
3, you get back the contents of cell 3 in the list, whaqtever that 
content is. so if cell 3 in a 6 celled list was "Ruby" then ALIST[3] 
would return the string "ruby".


It's easy to iterate lists. For instance:

   print ''
   for dir in ALIST:
   print '",dir,'
   print '

This would let me produce an ordered list of directories, each a link to 
that directory.
This way, when a client installs a new product, the home page area 
listing products offered automatically updates.


Further embellishment would let me replace the dir name with a BRIEF 
description from a descriptor file read from that dir. Now how to do 
this in php?


--
end

Very Truly yours,
- Kirk Bailey,
  Largo Florida

  kniht   
 +-+  
 | BOX |  
 +-+  
  think   



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] code quest

2010-11-26 Thread Adam Richardson
On Fri, Nov 26, 2010 at 7:03 PM, Kirk Bailey wrote:

> Hello all, my name is Kirk Bailey, and I am new to php, so please be
> forbearing. I code in python, and am trying to learn this language as our
> new client runs a web business based in it.
>
> I need a routine that will return a list of every directory immediately
> under the current directory- but nothing else, just a list of directories, 1
> level deep, NO FILES, no listing of current dir or prior dir either.
>
> Now in python, I would use os.walk, and use the list of dirs and throw the
> other 2 lists away, but this ain't Kansas anymore. Does php even DO lists?
>
> Um, a list is a 1 dimenional array, if have a list ALIST and you plug in 3,
> you get back the contents of cell 3 in the list, whaqtever that content is.
> so if cell 3 in a 6 celled list was "Ruby" then ALIST[3] would return the
> string "ruby".
>
> It's easy to iterate lists. For instance:
>
>   print ''
>   for dir in ALIST:
>   print '",dir,'
>   print '
>
> This would let me produce an ordered list of directories, each a link to
> that directory.
> This way, when a client installs a new product, the home page area listing
> products offered automatically updates.
>
> Further embellishment would let me replace the dir name with a BRIEF
> description from a descriptor file read from that dir. Now how to do this in
> php?
>
> --
> end
>
> Very Truly yours,
>- Kirk Bailey,
>  Largo Florida
>
>  kniht+-+
> | BOX |   +-+think
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
To get you started:

function get_directories($path)
{
   $files_and_dirs = scandir($path);
   $dirs = array_filter($files_and_dirs, function($elem) { return
is_dir($elem); });
   // $dirs also contains "." and "..", but you can get rid of them quite
easily
   return $dirs;
}

Happy coding :)

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com


Re: [PHP] code quest

2010-11-26 Thread Bastien




On 2010-11-26, at 7:33 PM, Adam Richardson  wrote:

> On Fri, Nov 26, 2010 at 7:03 PM, Kirk Bailey wrote:
> 
>> Hello all, my name is Kirk Bailey, and I am new to php, so please be
>> forbearing. I code in python, and am trying to learn this language as our
>> new client runs a web business based in it.
>> 
>> I need a routine that will return a list of every directory immediately
>> under the current directory- but nothing else, just a list of directories, 1
>> level deep, NO FILES, no listing of current dir or prior dir either.
>> 
>> Now in python, I would use os.walk, and use the list of dirs and throw the
>> other 2 lists away, but this ain't Kansas anymore. Does php even DO lists?
>> 
>> Um, a list is a 1 dimenional array, if have a list ALIST and you plug in 3,
>> you get back the contents of cell 3 in the list, whaqtever that content is.
>> so if cell 3 in a 6 celled list was "Ruby" then ALIST[3] would return the
>> string "ruby".
>> 
>> It's easy to iterate lists. For instance:
>> 
>>  print ''
>>  for dir in ALIST:
>>  print '",dir,'
>>  print '
>> 
>> This would let me produce an ordered list of directories, each a link to
>> that directory.
>> This way, when a client installs a new product, the home page area listing
>> products offered automatically updates.
>> 
>> Further embellishment would let me replace the dir name with a BRIEF
>> description from a descriptor file read from that dir. Now how to do this in
>> php?
>> 
>> --
>> end
>> 
>> Very Truly yours,
>>   - Kirk Bailey,
>> Largo Florida
>> 
>> kniht+-+
>>| BOX |   +-+think
>> 
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>> 
>> 
> To get you started:
> 
> function get_directories($path)
> {
>   $files_and_dirs = scandir($path);
>   $dirs = array_filter($files_and_dirs, function($elem) { return
> is_dir($elem); });
>   // $dirs also contains "." and "..", but you can get rid of them quite
> easily
>   return $dirs;
> }
> 
> Happy coding :)
> 
> Adam
> 
> -- 
> Nephtali:  PHP web framework that functions beautifully
> http://nephtaliproject.com


Code igniter, a php framework can do this with one call. It could be worth 
looking into

Bastien Koert
905-904-0334
Sent from my iPhone
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match fails to resolve variable as a subject

2010-11-26 Thread Da Rock

On 11/27/10 00:57, Richard Quadling wrote:

On 26 November 2010 00:07, Da Rock  wrote:
   

preg_match("/(\d{1,3})(\.)$/", exec($mixer . ' ' . $command),&$matches)
 

Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.

   

Haven't tried yet, but isn't that what $ is for? End of line?

And exec only gives one line- the last line of the output of the 
command. You have to provide a reference to an array for the entire output.


var_dump gives:
string(41) "Mixer vol is currently set to 75:75"

Any thoughts?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Richard West
Hey guys,
I've never run into this before.
I have a field in mysql for page views.
So I pull out value and do +1 to new value - after UPDATE SET it has 
incremented by 2?

$val = $row['a_downloads'] ;

$new_val = $val+1;

mysql_query("UPDATE cbn_articles SET a_downloads='$new_val' WHERE a_id = 
'".$_GET['id']."' ");

Any ideas? What am I missing?
RD
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match fails to resolve variable as a subject

2010-11-26 Thread Tamara Temple


On Nov 26, 2010, at 7:28 PM, Da Rock wrote:


On 11/27/10 00:57, Richard Quadling wrote:
On 26 November 2010 00:07, Da Rockl...@herveybayaustralia.com.au>  wrote:


preg_match("/(\d{1,3})(\.)$/", exec($mixer . ' ' . $command),& 
$matches)



Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.



Haven't tried yet, but isn't that what $ is for? End of line?




$ matches end of line, but since your last match expression is to  
match explicitly the character '.' before end of line, and there's a  
newline, it won't match. Again, use trim() to get rid of the newline  
character at the end of the string returned by exec(). Looking at the  
output or


And exec only gives one line- the last line of the output of the  
command. You have to provide a reference to an array for the entire  
output.


var_dump gives:
string(41) "Mixer vol is currently set to 75:75"



It also looks like \d{1,3}\. won't match anything in the output string  
given by the command.




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Tamara Temple


On Nov 26, 2010, at 8:36 PM, Richard West wrote:


Hey guys,
I've never run into this before.
I have a field in mysql for page views.
So I pull out value and do +1 to new value - after UPDATE SET it has  
incremented by 2?


$val = $row['a_downloads'] ;

$new_val = $val+1;

mysql_query("UPDATE cbn_articles SET a_downloads='$new_val' WHERE  
a_id = '".$_GET['id']."' ");


Any ideas? What am I missing?
RD


a_downloads wouldn't happen to be an autoincrement value, would it?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Tommy Pham
> -Original Message-
> From: Tamara Temple [mailto:tamouse.li...@gmail.com]
> Sent: Friday, November 26, 2010 7:54 PM
> To: Richard West
> Cc: PHP General Mailing List
> Subject: Re: [PHP] PHP Add +1 mysql updates by 2?
> 
> 
> On Nov 26, 2010, at 8:36 PM, Richard West wrote:
> 
> > Hey guys,
> > I've never run into this before.
> > I have a field in mysql for page views.
> > So I pull out value and do +1 to new value - after UPDATE SET it has
> > incremented by 2?
> >
> > $val = $row['a_downloads'] ;
> >
> > $new_val = $val+1;
> >
> > mysql_query("UPDATE cbn_articles SET a_downloads='$new_val' WHERE
> a_id
> > = '".$_GET['id']."' ");
> >
> > Any ideas? What am I missing?
> > RD
> 
> a_downloads wouldn't happen to be an autoincrement value, would it?
> 

IIRC, the auto_increment should only increment on an INSERT statement and
the field is omitted.  Besides, in MySQL, auto_increment must also be part
of the primary key.  From Richard's query, I'd say that his primary key
field is most likely a_id.  IMO, the best way to count something is to set
the field to an int(eger) type.  Then just run 'UPDATE table_name SET
count_field = count_field +1 WHERE criteria_column =  $criteria'.  This is
more safe as you many have simultaneous users downloading.  This would
ensure an accurate count, whereas your logic wouldn't.

Regards,
Tommy

PS:  Richard, you should validate and sanitize all inputs.  Your query is
prone to injection attack (deletion of rows or your entire DB deleted).  Use
either mysql_escape_string or, better yet, mysqli to prepare the statement
and bind the parameters.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match fails to resolve variable as a subject

2010-11-26 Thread Da Rock

On 11/27/10 13:51, Tamara Temple wrote:


On Nov 26, 2010, at 7:28 PM, Da Rock wrote:


On 11/27/10 00:57, Richard Quadling wrote:
On 26 November 2010 00:07, Da 
Rock  wrote:


preg_match("/(\d{1,3})(\.)$/", exec($mixer . ' ' . 
$command),&$matches)



Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.



Haven't tried yet, but isn't that what $ is for? End of line?




$ matches end of line, but since your last match expression is to 
match explicitly the character '.' before end of line, and there's a 
newline, it won't match. Again, use trim() to get rid of the newline 
character at the end of the string returned by exec(). Looking at the 
output or


And exec only gives one line- the last line of the output of the 
command. You have to provide a reference to an array for the entire 
output.


var_dump gives:
string(41) "Mixer vol is currently set to 75:75"



It also looks like \d{1,3}\. won't match anything in the output string 
given by the command.





Thank you for that- that did it. I removed the \.

I am a little confused though; that regex was tested on several test 
sites and was deemed accurate on them, and one of them actually supplied 
the preg_match code. And if I run the command on a shell it actually 
outputs exactly the right subject for the regex- not to mention it got 
printed inadvertently (using system() ) via the php exactly the same. So 
I don't think I missed it somehow.


What I have constantly seen come up (shell and php/html) is: Mixer vol 
is currently set to 75:75. (including the period)


Don't get me wrong- you guys make sense; my system doesn't. I need to 
get to the bottom of this so I can ensure my code will port well. I 
don't want to get it all working and find it breaks when I run it on 
another system, albeit same OS (FreeBSD). Could be updates or variations 
of releases.


Just to check again, I ran the command on the shell again and sure 
enough the period is no longer there- but I can't for the life of me 
figure out when that changed as this code has never worked (and yes, I 
added in the \. to match the end of line because it originally wasn't 
working). Another great mystery? Weird... :)


Thanks again guys.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Richard West
No


On Nov 26, 2010, at 10:53 PM, Tamara Temple wrote:

> 
> On Nov 26, 2010, at 8:36 PM, Richard West wrote:
> 
>> Hey guys,
>> I've never run into this before.
>> I have a field in mysql for page views.
>> So I pull out value and do +1 to new value - after UPDATE SET it has 
>> incremented by 2?
>> 
>> $val = $row['a_downloads'] ;
>> 
>> $new_val = $val+1;
>> 
>> mysql_query("UPDATE cbn_articles SET a_downloads='$new_val' WHERE a_id = 
>> '".$_GET['id']."' ");
>> 
>> Any ideas? What am I missing?
>> RD
> 
> a_downloads wouldn't happen to be an autoincrement value, would it?
> 
> 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Richard West
Hey Tommy,

I get the same when seting it to a_downloads=a_downloads+1  
It still increments by 2
I've never run into this before.
RD


On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote:

>> -Original Message-
>> From: Tamara Temple [mailto:tamouse.li...@gmail.com]
>> Sent: Friday, November 26, 2010 7:54 PM
>> To: Richard West
>> Cc: PHP General Mailing List
>> Subject: Re: [PHP] PHP Add +1 mysql updates by 2?
>> 
>> 
>> On Nov 26, 2010, at 8:36 PM, Richard West wrote:
>> 
>>> Hey guys,
>>> I've never run into this before.
>>> I have a field in mysql for page views.
>>> So I pull out value and do +1 to new value - after UPDATE SET it has
>>> incremented by 2?
>>> 
>>> $val = $row['a_downloads'] ;
>>> 
>>> $new_val = $val+1;
>>> 
>>> mysql_query("UPDATE cbn_articles SET a_downloads='$new_val' WHERE
>> a_id
>>> = '".$_GET['id']."' ");
>>> 
>>> Any ideas? What am I missing?
>>> RD
>> 
>> a_downloads wouldn't happen to be an autoincrement value, would it?
>> 
> 
> IIRC, the auto_increment should only increment on an INSERT statement and
> the field is omitted.  Besides, in MySQL, auto_increment must also be part
> of the primary key.  From Richard's query, I'd say that his primary key
> field is most likely a_id.  IMO, the best way to count something is to set
> the field to an int(eger) type.  Then just run 'UPDATE table_name SET
> count_field = count_field +1 WHERE criteria_column =  $criteria'.  This is
> more safe as you many have simultaneous users downloading.  This would
> ensure an accurate count, whereas your logic wouldn't.
> 
> Regards,
> Tommy
> 
> PS:  Richard, you should validate and sanitize all inputs.  Your query is
> prone to injection attack (deletion of rows or your entire DB deleted).  Use
> either mysql_escape_string or, better yet, mysqli to prepare the statement
> and bind the parameters.
> 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Peter Lind
On Saturday, November 27, 2010, Richard West  wrote:
> Hey Tommy,
>
> I get the same when seting it to a_downloads=a_downloads+1
> It still increments by 2
> I've never run into this before.
> RD
>
>
> On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote:
>
>>> -Original Message-
>>> From: Tamara Temple [mailto:tamouse.li...@gmail.com]
>>> Sent: Friday, November 26, 2010 7:54 PM
>>> To: Richard West
>>> Cc: PHP General Mailing List
>>> Subject: Re: [PHP] PHP Add +1 mysql updates by 2?
>>>
>>>
>>> On Nov 26, 2010, at 8:36 PM, Richard West wrote:
>>>
 Hey guys,
 I've never run into this before.
 I have a field in mysql for page views.
 So I pull out value and do +1 to new value - after UPDATE SET it has
 incremented by 2?

 $val = $row['a_downloads'] ;

 $new_val = $val+1;

 mysql_query("UPDATE cbn_articles SET a_downloads='$new_val' WHERE
>>> a_id
 = '".$_GET['id']."' ");

 Any ideas? What am I missing?
 RD
>>>
>>> a_downloads wouldn't happen to be an autoincrement value, would it?
>>>
>>
>> IIRC, the auto_increment should only increment on an INSERT statement and
>> the field is omitted.  Besides, in MySQL, auto_increment must also be part
>> of the primary key.  From Richard's query, I'd say that his primary key
>> field is most likely a_id.  IMO, the best way to count something is to set
>> the field to an int(eger) type.  Then just run 'UPDATE table_name SET
>> count_field = count_field +1 WHERE criteria_column =  $criteria'.  This is
>> more safe as you many have simultaneous users downloading.  This would
>> ensure an accurate count, whereas your logic wouldn't.
>>
>> Regards,
>> Tommy
>>
>> PS:  Richard, you should validate and sanitize all inputs.  Your query is
>> prone to injection attack (deletion of rows or your entire DB deleted).  Use
>> either mysql_escape_string or, better yet, mysqli to prepare the statement
>> and bind the parameters.
>>
>

Sounds like you're hitting the page twice. Check for missing image,
css files, favicons, js files etc.

-- 

WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Richard West
I took that into consideration so I added the update at the very end of 
document...
Still the same,
RD




On Nov 27, 2010, at 12:31 AM, Peter Lind wrote:

> On Saturday, November 27, 2010, Richard West  wrote:
>> Hey Tommy,
>> 
>> I get the same when seting it to a_downloads=a_downloads+1
>> It still increments by 2
>> I've never run into this before.
>> RD
>> 
>> 
>> On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote:
>> 
 -Original Message-
 From: Tamara Temple [mailto:tamouse.li...@gmail.com]
 Sent: Friday, November 26, 2010 7:54 PM
 To: Richard West
 Cc: PHP General Mailing List
 Subject: Re: [PHP] PHP Add +1 mysql updates by 2?
 
 
 On Nov 26, 2010, at 8:36 PM, Richard West wrote:
 
> Hey guys,
> I've never run into this before.
> I have a field in mysql for page views.
> So I pull out value and do +1 to new value - after UPDATE SET it has
> incremented by 2?
> 
> $val = $row['a_downloads'] ;
> 
> $new_val = $val+1;
> 
> mysql_query("UPDATE cbn_articles SET a_downloads='$new_val' WHERE
 a_id
> = '".$_GET['id']."' ");
> 
> Any ideas? What am I missing?
> RD
 
 a_downloads wouldn't happen to be an autoincrement value, would it?
 
>>> 
>>> IIRC, the auto_increment should only increment on an INSERT statement and
>>> the field is omitted.  Besides, in MySQL, auto_increment must also be part
>>> of the primary key.  From Richard's query, I'd say that his primary key
>>> field is most likely a_id.  IMO, the best way to count something is to set
>>> the field to an int(eger) type.  Then just run 'UPDATE table_name SET
>>> count_field = count_field +1 WHERE criteria_column =  $criteria'.  This is
>>> more safe as you many have simultaneous users downloading.  This would
>>> ensure an accurate count, whereas your logic wouldn't.
>>> 
>>> Regards,
>>> Tommy
>>> 
>>> PS:  Richard, you should validate and sanitize all inputs.  Your query is
>>> prone to injection attack (deletion of rows or your entire DB deleted).  Use
>>> either mysql_escape_string or, better yet, mysqli to prepare the statement
>>> and bind the parameters.
>>> 
>> 
> 
> Sounds like you're hitting the page twice. Check for missing image,
> css files, favicons, js files etc.
> 
> -- 
> 
> WWW: plphp.dk / plind.dk
> LinkedIn: plind
> BeWelcome/Couchsurfing: Fake51
> Twitter: kafe15
> 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Peter Lind
And what difference will that make if the document is requested twice with
every browser load?
On Nov 27, 2010 6:39 AM, "Richard West"  wrote:
> I took that into consideration so I added the update at the very end of
document...
> Still the same,
> RD
>
>
>
>
> On Nov 27, 2010, at 12:31 AM, Peter Lind wrote:
>
>> On Saturday, November 27, 2010, Richard West  wrote:
>>> Hey Tommy,
>>>
>>> I get the same when seting it to a_downloads=a_downloads+1
>>> It still increments by 2
>>> I've never run into this before.
>>> RD
>>>
>>>
>>> On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote:
>>>
> -Original Message-
> From: Tamara Temple [mailto:tamouse.li...@gmail.com]
> Sent: Friday, November 26, 2010 7:54 PM
> To: Richard West
> Cc: PHP General Mailing List
> Subject: Re: [PHP] PHP Add +1 mysql updates by 2?
>
>
> On Nov 26, 2010, at 8:36 PM, Richard West wrote:
>
>> Hey guys,
>> I've never run into this before.
>> I have a field in mysql for page views.
>> So I pull out value and do +1 to new value - after UPDATE SET it has
>> incremented by 2?
>>
>> $val = $row['a_downloads'] ;
>>
>> $new_val = $val+1;
>>
>> mysql_query("UPDATE cbn_articles SET a_downloads='$new_val' WHERE
> a_id
>> = '".$_GET['id']."' ");
>>
>> Any ideas? What am I missing?
>> RD
>
> a_downloads wouldn't happen to be an autoincrement value, would it?
>

 IIRC, the auto_increment should only increment on an INSERT statement
and
 the field is omitted. Besides, in MySQL, auto_increment must also be
part
 of the primary key. From Richard's query, I'd say that his primary key
 field is most likely a_id. IMO, the best way to count something is to
set
 the field to an int(eger) type. Then just run 'UPDATE table_name SET
 count_field = count_field +1 WHERE criteria_column = $criteria'. This
is
 more safe as you many have simultaneous users downloading. This would
 ensure an accurate count, whereas your logic wouldn't.

 Regards,
 Tommy

 PS: Richard, you should validate and sanitize all inputs. Your query is
 prone to injection attack (deletion of rows or your entire DB deleted).
Use
 either mysql_escape_string or, better yet, mysqli to prepare the
statement
 and bind the parameters.

>>>
>>
>> Sounds like you're hitting the page twice. Check for missing image,
>> css files, favicons, js files etc.
>>
>> --
>> 
>> WWW: plphp.dk / plind.dk
>> LinkedIn: plind
>> BeWelcome/Couchsurfing: Fake51
>> Twitter: kafe15
>> 
>


RE: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Tommy Pham
> -Original Message-
> From: Richard West [mailto:p...@cbnisp.com]
> Sent: Friday, November 26, 2010 9:40 PM
> To: Peter Lind
> Cc: Tommy Pham; Tamara Temple; PHP General Mailing List
> Subject: Re: [PHP] PHP Add +1 mysql updates by 2?
> 
> I took that into consideration so I added the update at the very end of
> document...
> Still the same,
> RD
> 


Things to consider as part of your application design/flow:

1) Are you doing all PHP processing (application initialization, DB
retrieval, user preference settings, etc.) before any header, echo, print,
printf, output buffer, etc... ?  At which point is the update done?
2) Are you sure the DB update is only called for or included/required once
for that particular URL request?
3) Do you any have other page (js - or in page ajax calls, css, php, html,
etc) that requests the page (with the update) again, as Peter mentioned?

It will help you if you do an UML or a flow chart of the application flow.

Regards,
Tommy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php