Re: [PHP] mysql_num_rows()

2011-02-22 Thread Daniel Molina Wegener
On Tuesday 22 February 2011,
Gary gp...@paulgdesigns.com wrote:

 Can someone tell me why this is not working?  I do not get an error
 message, the results are called and echo'd to screen, the count does not
 work, I get a 0 for a result...

  Are you sure that the table is called `counties` and not `countries`?

  :)

 
 
 
 $result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked')
 or die(mysql_error());
 
 if ( isset($_POST['submit']) ) {
 for($i=1; $i=$_POST['counties']; $i++) {
 if ( isset($_POST[county$i] ) ) {
 echo You have chosen . $_POST[county$i]. br/;
 }
 }
 }
 
 $county_total=mysql_num_rows($result);
 
 while($row = mysql_fetch_array($result))
 {$i++;
 echo $row['name'];
 }
 $county_total=mysql_num_rows($result);
 echo $county_total;
 
 echo 'You Have '  .  $county_total  .  ' Counties ';
 
 ?

Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/

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



Re: [PHP] array to var - with different name

2011-01-20 Thread Daniel Molina Wegener
On Thursday 20 January 2011,
Donovan Brooke li...@euca.us wrote:

 Hello again!
 
 I'm trying to find a good way to convert array key/value's to
 variable name values... but with the caveat of the name being
 slightly different than the original key
 (to fit my naming conventions).
 
 first, I (tediously) did this:
 
 ---
 if (isset($_GET['f_action'])) {
$t_action = $_GET['f_action'];
 }
 
 if (isset($_POST['f_action'])) {
$t_action = $_POST['f_action'];
 }
 
 if (isset($_GET['f_ap'])) {
$t_ap = $_GET['f_ap'];
 }
 
 if (isset($_POST['f_ap'])) {
$t_ap = $_POST['f_ap'];
 }
 ---
 
 Instead, I wanted to find *all* incoming f_ keys in the POST/GET
 array, and convert them to a variable name consisting of t_ in one
 statement.

  That was ver tedious...

 
 I then did this test and it appears to work (sorry for email line
 breaks):
 
 -
 $a_formvars = array('f_1' = '1','f_2' = '2','f_3' = '3','f_4' =
 '4','f_5' = '5','f_6' = '6',);
 
 $t_string = ;
 foreach ($a_formvars as $key = $value) {
if (substr($key,0,2) == 'f_') {
  $t_string = $t_string . t_ . substr($key,2) . =$value;
  parse_str($t_string);
}
 }
 -
 
 I figure I can adapt the above by doing something like:
 
 $a_formvars = array_merge($_POST,$_GET);
 
 However, I thought I'd check with you all to see if there is something
 I'm missing. I don't speak PHP that well and there may be an easier way.

  Did you tried the $_REQUEST variable?

  Take a look on:

  ?php echo var_dump($_REQUEST); ?

 
 Thanks,
 Donovan

Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


Re: [PHP] session_id() is not passed to the next page

2011-01-04 Thread Daniel Molina Wegener
On Tuesday 04 January 2011,
Michelle Konzack linux4miche...@tamay-dogan.net wrote:

 Hello,

  Hello...

 
 I am rewriting currently a login script and I encountered a problem with
 sessions.  While reading the two pages
 
 http://php.net/manual/de/function.session-start.php
 http://bugs.php.net/bug.php?id=14636

  Well, probably this is not a problem of PHP. You must try looking at
your page errors. The PHP session mechanism tries to write some headers
with the session ID (a cookie).

 
 I have not found a solution for my problem:
 
 8--
 function fncLogin($user, $pass, $redirect, $type='pam') {
 
   if ($user != '' and $pass != '') {
 
 $TEXT  = FONT size=\+2\ color=\red\BError/B/FONTbr
 /\n; $TEXT .= HR size=\3\ noshade=\noshade\\n;
 $TEXT .= The username does not exist or the password is wrong.p
 /\n; $TEXT .= p /\n;
 $TEXT .= Please go a href=\ . $_SERVER['HTTP_REFERER'] .
 \back/a and try it again.\n;
 
 if ($type == 'pam') {
 
   if (pam_auth($user, $pass, $PAM_ERR) === FALSE) {
 fncError('2', $TEXT, $errpage='false');
 exit();
   }
 
 } elseif ($type == 'shadow') {
 
   $shadow_file = DIR_HOST . /.shadow;
   if (is_file($shadow_file)) {
 
 $SHADOW = exec(grep \^ . $user . :\  . DIR_HOST . /.shadow
 |cut -d: -f2); if (empty($SHADOW)) {
 }
 
 $SALT=exec(grep \^$user:\  . DIR_HOST . /.shadow |cut -d:
 -f2 |cut -d$ -f1-3); $ENCRYPTED=crypt($pass, $SALT);
 if ($SHADOW != $ENCRYPTED) {
   fncError('2', $TEXT, $errpage='false');
   exit();
 }
 
   } else {
 $TEXT  = FONT size=\+2\ color=\red\BError/B/FONTbr
 /\n; $TEXT .= HR size=\3\ noshade=\noshade\\n;
 $TEXT .= This is a system error. I can not authenticate du to a
 missing config.\n; $TEXT .= p /\n;
 $TEXT .= Please inform the a href=\ . SYSAMIN .
 \sysadmin/a and try it later again.\n; fncError('1', $TEXT,
 $errpage='false');
 exit();
   }
 }
 
 session_register('sess_user');
 session_register('sess_timeout');
 $sess_user= $user;
 $sess_timeout = time() + 900;
 session_write_close();
 header(Location:  . $redirect);
   }
   exit();
 }
 8--
 
 which call the following page correctly, but the two vars $sess_user and
 $sess_timeout are empty.
 
 Can someone please tell me how to do this?

  Did you tried working with error_reporting(E_ALL) and looking if you have
the well known warning headers already sent?. Try to work with 
error_reporting(E_ALL), instead of hiding errors. If you get that warning
or error means that the cookie for session id was not written, so you can't
handle the session id on the next page...

  Try using session_start() as the very first call or session.auto_start = 1
in your php.ini (which is not recommended).

 
 Thanks, Greetings and nice Day/Evening
 Michelle Konzack


Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.


Re: [PHP] Flexible application plugin architecture, is this possible?

2011-01-04 Thread Daniel Molina Wegener
On Monday 03 January 2011,
Mike i...@snappymail.ca wrote:

 I'm trying to design a powerful plugin system that doesn't require any
 (or extremely little) modification to my existing large code base. Hook
 based systems unfortunately don't seem to meet this requirement.

  OK, that is a design problem...

 
 Is something like this possible in PHP?
 
 //Magic function I made up, similar to __call(),
 //only it replaces new $class with its own return value.
 function __instantiate( $class, $args ) {
 $plugin_class = $class.'Plugin';
 
 if ( file_exists( 'plugins/'.$plugin_class.'.php' ) {
 $obj = new $plugin_class($args);
 return $obj;
 } else {
 return new $class($args);
 }
 }
 
 class MainClass {
 function doSomething( $args ) {
 echo MainClass doSomething() called...\n;
 }
 }
 
 class MainClassPlugin extends MainClass {
 function doSomething( $args ) {
 echo MainClassPlugin doSomething() called...\n;
 
 //Modify arguments if necessary
 echo MainClassPlugin modifying arguments...\n;
 
 $retval = parent::doSomething( $args );
 
 //Modify function output, or anything else required
 echo MainClassPlugin post filter...\n;
 
 return $retval;
 }
 }
 
 $main_class = new MainClass();
 $main_class-doSomething( 'foo' );
 
 Results:
 MainClassPlugin doSomething() called...
 MainClassPlugin modifying arguments...
 MainClass doSomething() called...
 MainClassPlugin post filter...
 
 I realize PHP doesn't have this magical __instantiate function, but
 does it have any similar mechanism that would work to automatically
 load alternate classes, or have a class dynamically overload
 itself during runtime?

  Well, you can do this using abstract classes and interfaces. Also
you must try the autoloader:

  http://php.net/manual/en/language.oop5.autoload.php

  Probably this will help you a lot.

Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.


Re: [PHP] How does one reply to messages on this list?

2010-12-16 Thread Daniel Molina Wegener
On Thursday 16 December 2010,
Sam Smith a...@itab.com wrote:

 If I just hit 'Reply' I'll send my reply to the individual who created
 the message. If I hit 'Reply All' my reply will be sent to: Govinda 
 govinda.webdnat...@gmail.com, PHP-General List
 php-general@lists.php.net and the creator of the message.
 
 Neither option seems correct. What's up with that?

  If your MUA (or email client) is smart enough, it should have at least
Reply, Reply to Sender, Reply to All and Reply to Mailing List.
Here I have all those options.

 
 Thanks


Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.


Re: [PHP] sending email

2010-12-15 Thread Daniel Molina Wegener
On Wednesday 15 December 2010,
Marc Fromm marc.fr...@wwu.edu wrote:

 When I use the mail function on a linux server, how is the email sent?
 Does sendmail act alone or does it use SMTP?

  sendmail itself (or the replacement install, probably postfix or qmail)
is an MTA itself, so... it do not requires an SMTP server.

  You need to use SMTP server, you can try phpmailer, swift mailer and
related packages third party PHP libraries. You will need them, for example,
if your SMTP server requires authentication.

 
 Thanks
 
 Marc


Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.


Re: [PHP] http request

2010-12-05 Thread Daniel Molina Wegener
On Sunday 05 December 2010,
Moses jam...@gmail.com wrote:

 Hi Everyone,

  Hello...

 
 I would like to know whether there is a http request PHP script. I
 would like to use in cases where a background script is running for
 sometime and outputs the results in PHP once the script  has been
 executed.

  You can try cURL:

  http://php.net/manual/en/book.curl.php

 
 
 Thanks.
 
 musa


Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


Re: [PHP] Disk IO performance

2010-11-29 Thread Daniel Molina Wegener
On Sunday 28 November 2010,
Larry Garfield la...@garfieldtech.com wrote:

 There are many things that everybody knows about optimizing PHP code. 
 One of them is that one of the most expensive parts of the process is
 loading code off of disk and compiling it, which is why opcode caches
 are such a bit performance boost.  The corollary to that, of course, is
 that more files = more IO and therefore more of a performance hit.

  It depends on the implementation that PHP uses to open the file. For
example on Linux and similar operating systems, PHP uses the mmap(2)
function instead of read(2) or fread(2) functions, so it maps the complete
file into memory, that is more faster than using partial file reads.

 
 But... this is 'effin 2010.  It's almost bloody 2011.  Operating systems
 are smart.  They already have 14 levels of caching built into them from
 hard drive micro-controller to RAM to CPU cache to OS.  I've heard from
 other people (who should know) that the IO cost of doing a file_exists()
 or other stat calls is almost non-existent because a modern OS caches
 that, and with OS-based file caching even reading small files off disk
 (the size that most PHP source files are) is not as slow as we think.

  Yes, that's true. This point depends on how the operating system has
implemented it's VFS. Linux, FreeBSD and other platforms, have a well
done implementation of VFSs, so they have a good cache implementation
for concurrent reads, and first read on a file is made /hard/, then it
uses the cached file location (inode data).

 
 Personally, I don't know.  I am not an OS engineer and haven't
 benchmarked such things, nor am I really competent to do so.  However,
 it makes a huge impact on the way one structures a large PHP program as
 the performance trade- offs of huge files with massive unused code (that
 has to be compiled) vs the cost of reading lots of separate files from
 disk (more IO) is highly dependent on the speed of the aforementioned IO
 and of compilation.

  You can do your own benchmarks tests, from high level perspective or
low level perspective. If you want to trace performance on how PHP reads
files from the hard drive, you can use some extensions like xdebug.

  For example if you prefer to use require() and include(), instead of
require_once() and include_once() for concurrent reads, probably you
will get a lower performance because you will do real concurrent reads
on certain files.

 
 So... does anyone have any actual, hard data here?  I don't mean I
 think or in my experience.  I am looking for hard benchmarks,
 profiling, or writeups of how OS (Linux specifically if it matters) file
 caching works in 2010, not in 1998.

  Well, it also depends on the operating system configuration. If you
just want to know the performance of IO functions on PHP, I suggest to
use an extension like xdebug. It can generate profiling information to
be used with kcachegrind, so you can properly visualize how are working
IO functions in php.

  Probably a mmap(2) extension for PHP would be useful for certain kind
of files. The file_get_contents() function uses open(2)/read(2), so you 
can't do a quick on a file.

 
 Modernizing what everyone knows is important for the general community,
 and the quality of our code.
 
 --Larry Garfield

Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.


Re: [PHP] Form Processing

2010-11-29 Thread Daniel Molina Wegener
On Monday 29 November 2010,
Ron Piggott ron.pigg...@actsministries.org wrote:

 I am unable to retrieve the value of $referral_1 from:

  That's very simple, you are missing the name attribute for
your input elements, for example:

input type=text name=email
   maxlength=60 class=referral_5
   style=width: 400px;

  Should be:

input type=text name=email
   maxlength=60 class=referral_5 name=referral_5
   style=width: 400px;

  Please read the following links:

HTML Standards:
http://www.w3.org/standards/webdesign/htmlcss

PHP Manual:
http://cl.php.net/manual/en/

 
 $new_email = mysql_escape_string ( $_POST['referral_$i'] );
 
 why?
 
 PHP while lopp to check if any of the fields were populated:
 
 
 
 $i=1;
 while ( $i = 5 ) {
 
 $new_email = mysql_escape_string ( $_POST['referral_$i'] );
 
 if ( strlen ( $new_email )  0 ) {
 
 }
 
 }
 
 
 The form itself:
 
 
 form method=post action=”website”
 
 p style=margin: 10px 50px 10px 50px;input type=text name=email
 maxlength=60 class=referral_1 style=width: 400px;/p
 
 p style=margin: 10px 50px 10px 50px;input type=text name=email
 maxlength=60 class=referral_2 style=width: 400px;/p
 
 p style=margin: 10px 50px 10px 50px;input type=text name=email
 maxlength=60 class=referral_3 style=width: 400px;/p
 
 p style=margin: 10px 50px 10px 50px;input type=text name=email
 maxlength=60 class=referral_4 style=width: 400px;/p
 
 p style=margin: 10px 50px 10px 50px;input type=text name=email
 maxlength=60 class=referral_5 style=width: 400px;/p
 
 p style=margin: 10px 50px 10px 50px;input type=submit
 name=submit value=Add New Referrals/p
 
 /form
 
 
 What am I doing wrong?
 
 Ron
 
 The Verse of the Day
 “Encouragement from God’s Word”
 http://www.TheVerseOfTheDay.info

Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.


Re: [PHP] curl and variable parameters in hyperlink

2010-11-24 Thread Daniel Molina Wegener
On Wednesday 24 November 2010,
Bob Keightley bob.keight...@virgin.net wrote:

 I already have a curl script that gets the web page, but it doesn't pass
 the parameters

  Hello Bob,

 
 Being new to PHP I haven't the first idea how to modify it so that it
 does.
 
 Script is as follows:
 
 $url = http://www.xx.com/query.asp?param1=val1param2=val2;;
 
 foreach ($_POST as $key=$post) {
   $post=str_replace( , +, $post);
   $url.=$key.=.$post.;
   }


  Instead of concatenating strings, I suggest to use the http_build_query()
function:

?php
$data = array('param1' = 'val1',
  'param2' = 'val2',
  'param3' = 'val3');
$query = http_build_query($data);
echo Query: {$query}\n;
 ?

  So, to create a query string based on your $_POST request parameters,
you just need to use the function as follows:

?php
$query = http_build_query($_POST);
echo Query: {$query}\n;
 ?

  This will create the proper query string to be used on your URL.

 
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
 $data = curl_exec($ch);
 curl_close($ch);
 
 $data=str_replace('.asp', '.php', $data);
 echo $data;
 
 This returns the web page, but ignores val1 and val2 which are necessary
 to execute the query.


Best regards,
-- 
Daniel Molina Wegener dmw [at] coder [dot] cl
System Programmer  Web Developer
Phone: +56 (2) 979-0277 | Blog: http://coder.cl/


signature.asc
Description: This is a digitally signed message part.