Re: [PHP] Load Data infile

2004-05-13 Thread John W. Holmes
Juan Pablo Herrera wrote:

[snip]
I need do load data infile in mysql:
$query_string2 = LOAD DATA INFILE '/var/www/xls/test' REPLACE INTO
TABLE
`test` FIELDS TERMINATED BY ',' ENCLOSED BY '\' ESCAPED BY '\\' LINES
TERMINATED BY '\n';$query_db_string2 = mysql_query($query_string2);
But not realize nothing with execution the script.
[/snip]
have you checked mysql_error() ?


yes,
You have an error in your SQL syntax near ''' at line 2
but i change '\' and not work.
The problem is PHP parses the string before it's passed to MySQL.

Since you're using double quotes

ESCAPED BY '\\' LINES

is parsed to

ESCAPED BY '\' LINES

by PHP and then sent to MySQL, which causes an error.

Two solutions:

'ESCAPED BY \'\\\' LINES' (use single quotes)

or

ESCAPED BY '' LINES

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] md5() with rand() || Strange results, need help....

2004-05-13 Thread John W. Holmes
CF High wrote:

If anyone has any clues as to what might be happening; i.e. why the md5'd
submitted plain text password does not match the stored md5'd password,
please, please let me know.
md5() results in a 32 character string. What kind of field are you 
storing it in?

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Normalising Names

2004-05-13 Thread John W. Holmes
Justin French wrote:

Can someone point me in the direction of a function/library/tutorial on 
normalising and formatting user-inputted names so that they have the 
correct capitalisation etc?
I remember a discussion about this on the list a while ago 
(http://www.phparch.com/mailinglists/msg.php?a=681124s=geoff+caplanp=g=)

Here is the code that was eventually written to handle it: 
http://www.bigredspark.com/names.php

Hope it works.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] PHP Sessions on Windows

2004-05-12 Thread John W. Holmes
David Mitchell wrote:

I first attempted to edit the php.ini so that the session save path was
C:\Temp. No matter what I did, the save path always showed up in phpinfo()
as /tmp. So I created folder on the root of C: called tmp and everything
worked.
You were not editing the correct php.ini, then.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Reshuffling an array

2004-05-12 Thread John W. Holmes
From: Todd Cary [EMAIL PROTECTED]

 I do the following:

$eventList = array();
$eventList[] = Any;
$dbh = db_open($host, $user, $password, $database);
if($dbh) {
  $sthdl = db_get_event_data($dbh);
  while ($row = mysql_fetch_object($sthdl)) {
$eventList[] = $row-EV_EVENT;
  }
} else {
  $eventList[] = * None found *;
}
asort( $eventList );

 Now I want to put Any as the first item.  What is the best way to do
 this?  Often the sort puts it as an item down the list.

Remove the line adding 'Any' at the beginning of your code and use
array_unshift() to add it at the end.

   $eventList = array();
   $dbh = db_open($host, $user, $password, $database);
   if($dbh) {
 $sthdl = db_get_event_data($dbh);
 while ($row = mysql_fetch_object($sthdl)) {
   $eventList[] = $row-EV_EVENT;
 }
   } else {
 $eventList[] = * None found *;
   }
   asort( $eventList );
   array_unshift($eventList,'Any');

do you really need to maintain the numeric keys to the array by using
asort() instead of just sort()? If so, this may not work. You may be able to
use array_splice($input, 0, 0, array('Any')) or array_merge().

---John Holmes...

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



Re: [PHP] PHP Session Handlers

2004-05-12 Thread John W. Holmes
From: Paul Higgins [EMAIL PROTECTED]

 I just read this tutorial:
 http://www.phpbuilder.com/columns/ying2602.php3

 I understand what each function does and what to do in each function.
 However, my question is this:  If I write my own session handling
functions,
 do I have to explicity call them myself?  If so, when do I call them?

No, you'll just use sessions as normal and these functions will be used by
PHP when needed. For instance, at the end of the script when PHP needs to
save the current session variables, it'll call your write() function. You
just use sessions as normal, though.

---John Holmes...

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



Re: [PHP] HTTP_RAW_POST_DATA

2004-05-11 Thread John W. Holmes
From: Curt Zirzow [EMAIL PROTECTED]
 * Thus wrote John W. Holmes ([EMAIL PROTECTED]):
  
  Check the value of always_populate_raw_post_data in php.ini on both
  servers.
 
 Thats such a funny name.

So is Zirzow

---John Holmes...

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



Re: [PHP] working with forms - loosing data on back button

2004-05-11 Thread John W. Holmes
From: Merlin [EMAIL PROTECTED]

 The problem I have, is that the publishing is split into 3 screens
(steps). If
 the user reaches form 2, types something in and clicks on back and then on
 forward again he looses the values of the data entered in form 2.

 The back button is done with: javascript:history.back(); so it is totally
clear
 that the value of the present form is gone. But how to put two different
actions
 into one form? One for next, one for back? Do you see the problem?

 I would like to avoid saving to a database before the user does not finish
the
 whole process. There must be another solution. I guess this is a standard
 problem and I do just not see the solution?!

Save it into the session as they go through the three pages and only save it
into the database at the end.

Keep track of a $page variable and increment or decrement based on whether
they chose the Next or Prev button and show the appropriate content for
the $page.

---John Holmes...

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



Re: [PHP] session names

2004-05-11 Thread John W. Holmes
From: Edward Peloke [EMAIL PROTECTED]

 It is necessary to always name your sessions?or is session_start()
 sufficient?

No. Yes.

---John Holmes...

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



Re: [PHP] php|works

2004-05-11 Thread John W. Holmes
From: John Nichel [EMAIL PROTECTED]

 Who's going (thinking about) to this?

 http://www.phparch.com/phpworks/

Where is this Canada they speak of?? ;)

I know Marco will put on a good show for this; definitely go if you can.
I'll be in school, so I don't plan on going unless I come up with some
facinating subject to speak on! :)

---John Holmes...

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



Re: [PHP] HTTP_RAW_POST_DATA

2004-05-11 Thread John W. Holmes
From: Chris Boget [EMAIL PROTECTED]

 On our development server, I have a script that accesses the
 value of $HTTP_RAW_POST_DATA (upon form submission)
 and there is data there.  However, on our production server,
 the same code shows no value held in $HTTP_RAW_POST_DATA.
 Both servers are running v4.3.2 and as far as I can tell, have the
 same configuration.  Where would I look to discover why one
 server would have data held in $HTTP_RAW_POST_DATA
 whereas the other server would not?

Check the value of always_populate_raw_post_data in php.ini on both
servers.

---John Holmes...

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



Re: [PHP] Remove cahracters in string

2004-05-10 Thread John W. Holmes
Mike Mapsnac wrote:

I search on php.net and couldn't find the function. I need a function 
that will remove characters in the string  until it reached the pattern 
and remove characters in the string after another pattern.

The program reads huge file, and remove unnessary data.
So I need to remove characters before and after the line.
Wouldn't it be smarter to match the pattern into a new string and ignore 
the rest??

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] How to find path for PHP script

2004-05-10 Thread John W. Holmes
From: Daniel Clark [EMAIL PROTECTED]

  Does anyone know a quick way to find the full path on a shared hosting
  plan to use in an include file?

 What about:

 $_SERER['PATH_TRANSLATED']

If you note my message from yesterday, I was having some trouble with this
variable on certain configurations. You may want to use
$_SERVER['SCRIPT_FILENAME'] which will have the same value and seems to be
present in more cases (or just test for both).

---John Holmes...

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



Re: [PHP] Accessing the values of objects

2004-05-10 Thread John W. Holmes
From: John Nichel [EMAIL PROTECTED]

 Yeah, I get an empty value for the object I'm working with (quite a bit
 bigger than the example I posted) when I try to retrive the individual
 value, but the print_r of the object shows that it has value.  I thought
 my syntax was wrong, but I guess I have to keep digging to find out
 where the 'trouble' is.  Thanks for the help.

Try going step by step. You know the results of print_r($bob), now
print_r($bob-_four) and examine the results. Then
print_r($bob-_four['gamma']), etc... may help you track down where
something is going wrong...

---John Holmes...

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



Re: [PHP] Clean Open Source PHP extranet app?

2004-05-09 Thread John W. Holmes
david david wrote:

I am looking to create a simple extranet type
application similar to http://www.basecamphq.com/
written by 37signals.
Basically I just need a way for users to share
files/projects/messages.  
Maybe PHProjekt?

http://www.phprojekt.com/

I'm sure hotscripts.com will have others.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


[PHP] Does this directory detection script work for you?

2004-05-09 Thread John W. Holmes
Hello. I'm relying on the following code so that a script can 
automatically detect where it's installed and create paths and URLs from 
the information. This way absolute paths and URLs are always used.

I've had a couple people report that the script wasn't finding the paths 
correctly, though, so I'm asking if people could test this out on their 
server and see if it detects the paths or not.

?php
//Install path (path to survey.class.php)
$path = dirname($_SERVER['PATH_TRANSLATED']);
//Determine protocol of web pages
if(isset($_SERVER['HTTPS'])  
strcasecmp($_SERVER['HTTPS'],'ON') == 0)
{ $protocol = 'https://'; }
else
{ $protocol = 'http://'; }

//HTML address of this program
$dir_name = dirname($_SERVER['SCRIPT_NAME']);
if($dir_name == '\\')
{ $dir_name = ''; }
$html = $protocol . $_SERVER['SERVER_NAME'] . $dir_name;

//Determine web address of current page
$current_page = $protocol . $_SERVER['SERVER_NAME'] . 
$_SERVER['SCRIPT_NAME'];

echo Path to script: $pathbr /;
echo URL to script directory: $htmlbr /;
echo URL to current script: $current_page;
?
It should print out the file system path to where the script was placed 
as well as a URL to the directory it was placed and a URL to the file 
itself.

I've never had an issue with it personally and I've tested it on Apache 
and IIS on both Windows and Linux. So maybe it's some obscure CGI or OS 
configuration where this isn't working? I just need to know so I can 
plan accordingly.

The only two substitutions that can be made (that I know of) are:

$_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF']
and
$_SERVER['PATH_TRANSLATED'] = $_SERVER['SCRIPT_FILENAME']
If it doesn't work for you, does it work if you do one of those 
substitutions?

Also, this will test if the script is in subdirectories or not, also, so 
testing it within one and seeing if that works, too, is appreciated.

Thanks for any help and time you're willing to provide.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Showing only part of string

2004-05-07 Thread John W. Holmes
Dave Carrera wrote:

$string = This is a test string to titleSHOW ONLY THIS BIT/title of the
string;
I have tried strpos, str_replace and other string manipulation things but I
cant get my head around how to achieve showing the text with the
title/title tags of the string.
Any help is appreciated and I thank you in advance for any help given.
$b = strpos($str,'title')+7;
$l = strpos($str,'/title') - $b;
$m = substr($str,$b,$l);
Sure, you can use regular expressions, but there's not really a need 
unless this gets more complex. Even though you're executing more code 
with this solution, it'll be faster than preg_match() (go ahead and 
benchmark it).

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Active PHP Sessions

2004-05-07 Thread John W. Holmes
From: Jason Wong [EMAIL PROTECTED]

 i) There is no way to determine which session files are for your site
without
 actually examining their contents.

 ii) PHP does not store any site identification info in the session files.

 iii) Hence you need to store a (hopefully) unique string in all your
sessions
 then search for this string in the session files.

You have the option of using session_save_path() and using a directory of
your own to store the session files. Then the active session count is just
a count of how many files exist in that directory. You have to implement
your own garbage cleanup of the session files, though.

---John Holmes...

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



Re: [PHP] #209;

2004-05-07 Thread John W. Holmes
From: Curt Zirzow [EMAIL PROTECTED]
 * Thus wrote Diana Castillo ([EMAIL PROTECTED]):
  we are recieving  Ñ as #209;
  ¿what type of code is that?

 Thats an html entity code.

  Is there a function in php to convert it?

 echo chr(substr('#209;', 2, 3));

also,

http://us2.php.net/manual/en/function.html-entity-decode.php

---John Holmes...

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



Re: [PHP] form submission logic

2004-05-07 Thread John W. Holmes
From: Aaron Wolski [EMAIL PROTECTED]

 Within the form/form tags I have my buttons - Publish, Unpublish,
 New, Edit and Delete.

 Next I have a table of that displays a list of records from a database
 with a checkbox to select a particular record.

 Once a record has been selected they click one of the top buttons to
 perform their desired action.

 WILL this work OR do the buttons HAVE to go at the bottom?

The buttons can go anywhere inside the form tags. Since this is a PHP
list, though, you should really be asking is how would this form best work
with PHP to perform each desired action?

---John Holmes...

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



Re: [PHP] page_title

2004-05-07 Thread John W. Holmes
Erik Gjertsen wrote:

head
title/title
meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
/head
body
?php
$page_title = Welcome;
Hmmm... you're title doesn't show up? Are you using sessions? Is 
safe_mode on or off? Is html_title_mode on or off in your php.ini file?

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Re: strip comments from HTML?

2004-05-06 Thread John W. Holmes
Justin French wrote:

$text = preg_replace('/!--.*--/su','',$text);
Did not work (was too greedy, matched multiple comments)
Just for the record, it should be a capital 'U' for ungreedy. Lowercase 
'u' is something else. :)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Returning an object

2004-05-06 Thread John W. Holmes
Aidan Lister wrote:

Please don't reply if you really, really don't know what you are talking
about.
Okay, I won't reply.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] strip comments from HTML?

2004-05-06 Thread John W. Holmes
From: Justin French [EMAIL PROTECTED]

 This isn't working:
 $text = preg_replace('/!--(.*)--/','',$text);

 Can someone advise what characters I need to escape, or whatever to get
 it going?

$text = preg_replace('/!--.*--/su','',$text);

The 's' modifier will allow the expression to pick up multi-line comments by
allowing the dot character to match newlines and the 'u' modifier makes it
'ungreedy', so that if you have

!-- comment 1 --
HTML example
!-- comment 2 --

only the comments themselves are matched and not everything from the first
!-- to the last --.

---John Holmes...

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



Re: [PHP] Way OT MySql Update

2004-05-06 Thread John W. Holmes
From: Dave Carrera [EMAIL PROTECTED]
 I have a date column and have added a datenew column and want to do a
table
 wide update to make datenew 1 year more that date.

UPDATE yourtable SET datenew = dateorig + INTERVAL 1 YEAR;

Although... if datenew is always one year more than dateorig, why would
you need another column?

SELECT dateorig, dateorig + INTERVAL 1 YEAR AS datenew, ... FROM ...

??

---John Holmes...

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



Re: [PHP] Looking for Advanced PHP Developers

2004-05-06 Thread John W. Holmes
From: Ammar Ibrahim [EMAIL PROTECTED]

 I don't understand what you mean.

Please take any further discussion off-list. I can handle off topic posts,
but the safety of caucasians in Jordan is too much of a stretch, I think.
:)

---John Holmes...

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



Re: [PHP] Re: strip comments from HTML?

2004-05-06 Thread John W. Holmes
From: Rob Ellis [EMAIL PROTECTED]
 you can make the .* less greedy...

   $text = preg_replace('/!--.*?--/', '', $text);

You still need an 's' modifier if you want to match multi-line comments. The
dot character won't match newlines unless you use an 's' modifier.

---John Holmes...

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



Re: [PHP] Sending Mail with PHP

2004-05-06 Thread John W. Holmes
From: Justin @ Dreaming in TO [EMAIL PROTECTED]
 If you go to http://www.functionjunkie.org/contactform/contactform.php
 and fill out the form, it sends the email ok, but its supposed to
 redirect to a preset page, which it does.

 However, the page it redirects to is blank, except for the background
 image that is referenced in the CSS stylesheet. Feel free to test it as
 many times as you would like.
[snip]
 mail($mailto, $subject, $messageproper, From: \$name\
 $email\nReply-To: \$name\ $email\nX-Mailer: FunctionJunkie
 WebMailer );
  exit ;

1. I don't see where you're redirecting anywhere after you send the mail().

2. You have output on line 7 of feedback.php, which means your header()
redirects will fail, anyhow.

3. This script is vulnerable to mail header injection attacks because you do
not check the user-supplied data for newlines. A maliciously formed $name or
$email value could lead to header injection.

4. You should use \r\n between your additional mail headers.

---John Holmes...

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



Re: [PHP] problem with a while loop

2004-05-06 Thread John W. Holmes
From: Jessica Mays [EMAIL PROTECTED]
 I am new to php (and mySQL) and I am working on a php page that links
 up to a mySQL database.  My current code works up to a point, BUT what
 happens is that I try to have a while loop and check a variable with an
 inner while loop but it only catches after the first complete cycle.

while ($i  $num_results)   {

 $row = mysql_fetch_array($result);

   $producer = $row[PRODUCE];
[snip]
 while (  $producer == $row[PRODUCE]) {

 $row = mysql_fetch_array($result);
[snip]
 ++$i;
 }

 ++$i;
}

You posted too much code to go through easily. It took me a while to figure
out what you were doing. The code above is what it really could have been
condensed to...

Anyhow, the first time through, you're inner while() loop is always going to
execute and keep executing until you pull a new produce value from the
result set. At that time, the new produce row is currently in $row, the
inner while() loop fails and control passes back to your outer loop.
However, at that time you call mysql_fetch_array() again in your outer loop
and you just lost the row that cause the inner loop to teminate.

What you want, if I can read right, is to only display the part in your
outer while() loop when produce changes.

$producer = '';
while($row = mysql_fetch_array($result))
{
  if($row['produce'] != $producer)
  {
//display outer while() loop HTML here
$producer = $row['produce'];
  }
  //display inner while() loop HTML here.
}

Hope that helps.

---John Holmes...

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



Re: [PHP] problem with a while loop

2004-05-06 Thread John W. Holmes
From: John Nichel [EMAIL PROTECTED]

$i =0;
 
while ($i  $num_results)   {
 
  $row = mysql_fetch_array($result);
 
   $producer = $row[PRODUCE];
 snip

 Try changing the above from

 while ($i  $num_results)   {

  $row = mysql_fetch_array($result);

 To

 while ( $row = mysql_fetch_array($result) ) {

Same thing, really. It's a little more efficient than keeping a count, but
not the cause of any of the problems. :)

---John Holmes...

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



Re: [PHP] problem with a while loop

2004-05-06 Thread John W. Holmes
From: John Nichel [EMAIL PROTECTED]

  Same thing, really. It's a little more efficient than keeping a count,
but
  not the cause of any of the problems. :)
 
  ---John Holmes...

 Chris!  John is picking on me!

I thought we agreed that Chris is the one that cannot be trusted??

---John Holmes...

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



Re: [PHP] textarea and quotes

2004-05-05 Thread John W. Holmes
From: Vincent DUPONT [EMAIL PROTECTED]

 I can't remember the name of the function to remove 
 the escaping of quotes when submitting a textarea
 example : 
 tr class=content_title
 becomes : 
 tr class=\content_title\
 stripslashes and stripcslashes seem not to work...

stripslashes() works, just make sure you capture the result.

example:
$newstr = stripslashes($oldstr);
and not:
stripslashes($oldstr);

---John Holmes...

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



Re: [PHP] form validation wih html input FILE

2004-05-05 Thread John W. Holmes
From: Vincent DUPONT [EMAIL PROTECTED]

 I'd like your opinion on the best way to do a form
 validation when the form contains a file upload object
 (input type=file)

 When the form does not validate, I try to re-show all values
 entered by the user.But, as far as I know, browsers do not
 allow to set the default value (local file path) of a FILE component
 I can get and display the default value in a label or text input,
 but how could I upload that file then? Will I be limited to display
 a warning message indicating that the user will have to select his/her
file again??

You're not going to be able to fill it in for them. There's no way around
that (which is a good thing).

Solutions are to either notify them to select the file again and hope they
notice, or keep the file in a temp directory when it's uploaded the first
time and call it from there when the validation is successful. Simply remove
the input type=file from the form when you have the file, but make them
correct / validate the rest of the data. Then, you know that if $_FILES is
empty, you can search in the temp directory according to a hidden field /
session value you've set to look for the file. Retrieve it from there and
proceed as normal.

---John Holmes...

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



Re: [PHP] paging methodology

2004-05-05 Thread John W. Holmes

- Original Message - 
From: Paul Chvostek [EMAIL PROTECTED]
 On Tue, May 04, 2004 at 02:37:50PM -0700, Chris W. Parker wrote:
  well that just meant that after the initial count of records is found it
  will be retrieved from the querystring instead of through a select
  statement (because it had already been performed once before).

 I never bother with getting the initial record count.  Unless you want
 to display the total number of available pages, of course (in the vein
 of Google search result set).

Personal preference here, I guess, but I don't care for searches that don't
tell you how many records were matched (or how many pages you'll have). I
think the additional query is well worth it. The number of results tells me
how successful my search was and whether I need to expand or shrink my
search criteria.

---John Holmes...

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



Re: [PHP] HTTP_REFERER ... ?

2004-05-05 Thread John W. Holmes
From: Pablo Gosse [EMAIL PROTECTED]

 The following is quoted from a previous post by Chris Shifflet:
 
 Referer is just as easy to spoof as the form data you're expecting.

wait, wait, wait... we CAN'T trust form data? Crap...

---John Holmes...

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



Re: [PHP] paging methodology

2004-05-05 Thread John W. Holmes
From: Chris W. Parker [EMAIL PROTECTED]

 do you know if that's any faster than doing a SELECT COUNT(*) FROM
 table WHERE ... ?

I did a couple (unscientific) tests and there doesn't seem to be much of a
difference. I'd use the COUNT(*) method just because it's more portable,
though.

---John Holmes...

mysql select count(id) from status_history where date between
2004010100 AND 2004050100;
+---+
| count(id) |
+---+
| 27791 |
+---+
1 row in set (0.13 sec)

mysql select * from status_history where date between 2004010100 AND
2004050100 LIMIT 2000,100;
100 rows in set (0.02 sec)

mysql select SQL_CALC_FOUND_ROWS * from status_history where date between
2004010100 AND 2004050100 LIMIT 2000,100;
100 rows in set (0.14 sec)

mysql select found_rows();
+--+
| found_rows() |
+--+
|27791 |
+--+
1 row in set (0.00 sec)

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



Re: [PHP] paging methodology

2004-05-05 Thread John W. Holmes
From: Chris W. Parker [EMAIL PROTECTED]

 on a related note... how does BENCHMARK() work? i don't understand their
 explanation. the reason i ask is because i'd like to test our the
 efficiency of what you are suggesting compared to what i am currently
 doing.

 SELECT BENCHMARK(500, 'SELECT * FROM table');

 although that didn't throw an error, it didn't seem to do anything
 either.
Getting OT here...

From what I understand, you can't use complete queries in benchmark, only
expressions. So, what you're actually benchmarking there is setting a
string, I guess.

You can use it for something like this, though:

SELECT BENCHMARK(50,5 BETWEEN 0 AND 10);

and...

SELECT BENCHMARK(50,0  5 AND 5  10);

to see which method MySQL handles faster (between benchmarks faster,
although I've always been lead to believe the  and  method is faster). I
don't know if i'd really interpret much from the results, though..

---John Holmes...

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



Re: [PHP] It opens the file instead downloading

2004-05-05 Thread John W. Holmes
From: Phpu [EMAIL PROTECTED]

 header( Content-type: application/force-download );
 if ((is_integer (strpos($user_agent, msie)))  (is_integer
(strpos($user_agent, win {
   header( Content-Disposition: filename=.$filename);
 } else {
   header( Content-Disposition: attachment; filename=.$filename);
 }
 header( Content-Description: File Transfert);
 @readfile($file_to_download);

 Instead downloading the file the script opens it.

Why are you not sending attachment if it's IE? I simply use:

header(content-type: application/vnd.ms-excel; name='excel');
header(content-disposition: attachment; filename= . $filename .
.xls);

and haven't had any trouble. You'll obviously want to adjust the
content-type, but I still send attachment.

---John Holmes...

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



Re: [PHP] String Question

2004-05-02 Thread John W. Holmes
Dave Carrera wrote:
How would I show 100 chars after finding the first instance of a searched
word in a string.
$start = strpos('hello',$str);
$hundredchars = substr($str,$start,100);
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] sessions failing to persist

2004-05-02 Thread John W. Holmes
Michael R. Wayne wrote:
   form method=post action=xxx.php
  input type=text maxlength=7 size=7 name=field value=?echo $_POST['field']?
  input type=submit value=Submit
   /form
Try adding in a hidden element

input type=hidden name=PHPSESSID value=?=session_id();?

You're relying on PHP rewriting your forms, links, etc, to include the 
session id, but that doesn't seem to be happening.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Select from 24 tables

2004-05-01 Thread John W. Holmes
Dave Carrera wrote:

Hi List,

How do I select data from 24 table in my database.

Each one is identical in structure layout being

Id,name,list
The first thing you need to do is reorganize your database schema and 
put all of this into one table. You can see what a pain it is having 24 
similar tables already and it's only going to get worse.

You could probably use a UNION to join all of the tables together in 
your query, but I doubt it's going to very efficient. You can't select 
from a list of tables the way you're trying to, though.

Last option is putting your query in a loop and executing it 24 
different times, but you _really_ need to just fix the database 
structure now.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] string replace in files

2004-04-30 Thread John W. Holmes
From: Steve Buehler [EMAIL PROTECTED]

 I am trying to write a script that will replace a string in a
 file.  Actually, about 3000 files.  And I am stuck.  I can get the list of
 files, but then I pretty much become stuck.  I wanted to try str_ireplace
 (not sure if that is what I should use or not), but I can't even get far
 enough to do that.  I am hoping that someone out there has an easy
response
 to this.  Below is the code that I have so far.
 Thanks
 Steve

 #!/usr/bin/php
 ?
 $strtoreplace=require \http://www.domain.com/;;
 $replacewithstring=require \/home/domain/www/;

 replacestring();

 function replacestring(){
 GLOBAL $strtoreplace,$replacewithstring;
  $FILES=array(`ls -1 */*|grep .php`);
  foreach($FILES as $value){
  if($value){
  echo file $value\n;

$content = file_get_contents($value);
$content = str_replace($strtoreplace,$replacewithstring,$content);
$fp = fopen($value,'w');
fwrite($fp,$content);
fclose($fp);

  }
  }
 }
 ?

You could use glob() to get the list of files, too.

$FILES = glob('*.php');

---John Holmes...

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



Re: [PHP] string replace in files

2004-04-30 Thread John W. Holmes
From: Steve Buehler [EMAIL PROTECTED]

  Thank you so much for this.  I was thinking of it all wrong when
 doing this.   I have a couple of other questions to go along with this.
 1.  How would I change this to do a recursive search for the .php files
 instead of just the *.php or */*.php in the glob?

Make a recursive function and use the opendir() / readdir() functions. Use
is_dir() to see if the file is a directory, and if so, call the function
again passing the new directory. If it's not, grab the last four characters
looking for .php to see if you should open/replace/rewrite the file.

 2.  I also have some dns zone files that I was going to modify this script
 to replace some information in them.  What it would have to do is to
delete
 all lines that have white space (could be a space or a tab) NS more white
 space and then add specific lines that I want in place of the deleted
lines.
  2.a.  There will normally be between 2 and 4 lines that I want
 deleted and 2 to replace them.

Same method. You'd probably want to use a regular expression to get rid of
the lines and insert the replacement text.

---John Holmes...

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



Re: [PHP] dollar sign ASCII code

2004-04-30 Thread John W. Holmes
David T-G wrote:

I have a comment field where I allow users to enter the picture comments
and then I later display them.  I thought I was converting everything as
needed (I inherited the code), but using a dollar sign breaks things (I'm
sure PHP is trying to interpret it).
The proper fix, I know, is to go and properly convert that dollar sign,
too; we will, but of course we have to test the new code before we roll
it out -- and we have to pin down why it isn't doing it now in the first
place.  The quick fix, though, is to tell him to use the proper HTML
escape sequence for it, like #039; for an apostrophe or amp; for an
ampersand.
Does anyone have the code for a dollar sign?
http://www.asciitable.com/

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Re: $_SERVER['SERVER_NAME'] in read-only.

2004-04-29 Thread John W. Holmes
From: Red Wingate [EMAIL PROTECTED]

 AFAIK the content of the superglobal variables cannot be changed ( even
 though i haven't found this in the docs i can remeber got beaten by PHP
 for doing so :-) )

They can be changed and you can even add to them.

$_SERVER['foo'] = 'bar';

is valid and now it's a superglobal, too. I wouldn't recommend relying on
this, though.

If you talking about the users changing the values of of superglobals then
that's different. Users can't directly set $_SERVER values, for example, but
they can pass values that may influence them. $_SERVER['HTTP_REFERRER']
comes from what the user supplies, for instance, so they are able to
manipulate it. A user would not be able to set $_SERVER['SERVER_NAME'] or
$_SERVER['PHP_SELF'], though. Which ones are safe or not just takes some
research or asking. :)

---John Holmes...

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



Re: [PHP] how to verify PHP has been installed with ldap?

2004-04-29 Thread John W. Holmes
From: Bing Du [EMAIL PROTECTED]

 So my question is how to verify PHP has been installed with ldap support?

?php phpinfo(); ?

And see if there is an ldap section.

---John Holmes...

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



Re: [PHP] re-keying an array

2004-04-29 Thread John W. Holmes
Justin French wrote:
been RTFMing for about 10 minutes, and can't find the function to re-key 
an array.  In other words, I want an array of items to remain in their 
current order, but have the keys renumbered counting from zero.

yes, I know it can be done with a foreach, but I was hoping for 
something native :)

can anyone point me to the right page in the manual?
array_values()

$newarray = array_values($old_array);

Although this begs the question of why you'd need to rekey an array...

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] re-keying an array

2004-04-29 Thread John W. Holmes
Justin French wrote:
On 30/04/2004, at 12:06 PM, John W. Holmes wrote:

Although this begs the question of why you'd need to rekey an array...
It seemed the easiest way to get the first two elements off the 
beginning of the array after shuffle()ing it, or so I thought -- but I'm 
more than happy to hear of a better way, as always :)

My only requirement is really to end up with an array named $files that 
can be used later on in the template in a foreach loop.

?
shuffle($filenames);// random sort
$filenames = array_values($filenames);// re-key
for($i=0;$i2;$i++) {
$files[] = path/to/.$filenames[$i];
}
?
... then in the template:

? foreach($files as $file): ?
div ...
...
? include($file); ?
...
/div
? endforeach; ?
Like I said, always happy to see something in a few less lines :)
If I'm following what you want to do correctly:

for($i=0;$i2;$i++)
{
  $key = array_rand($filenames);
  $files[] = path/to/.$filenames[$key];
  unset($filenames[$key]);
}
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] mouse over problem on php

2004-04-24 Thread John W. Holmes
gowthaman ramasamy wrote:
hi list ,
Hi. This has nothing to do with PHP.

In the web page, i display different bars (actually tables with single
column, with cellpadding=1 and color=xxx) based on the information
parsed from MySQL database. I, now want to display more information by
mouse over when ever user moves the cursor over the bar(actually single
cell table).
I use a hreff=xx.xx.com title=$display ./a. and  have two
problems in this ...
1) i need to have some txt/figure to be linked. But i dont want to keep
any thing in the table (single cell). Can i display some text when mouse
is moved over table(cell).
If you want hyperlinks and other features in the mouse over area, then 
you'll need to make it a layer that's hidden or not based upon where the 
mouse is. You're talking DHTML/JavaScript here, not PHP.

2)even if i hyperlink  the text with title attribute... only the text
before the first space (the very first word) is displayed. Not the
entire sentence.
Put double quotes around your attributes. title=$display. Again, not a 
PHP issue.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] A security thing or just sessions working?

2004-04-24 Thread John W. Holmes
[EMAIL PROTECTED] wrote:

Hi

I had a problem with what my host called a spate of insecure PHP
applications being used to upload proxying applications which I think has
been solved, however I've just spotted this when trying to validate my
HTML:
form action=abc.php4 method=postinput type=hidden
name=PHPSESSID value=aada9a6f795cb72df1ef8b8f61d2715c /div
class=secondColThirdinput type=submit value=register/div/form
The HTML validator wants the input type to be within the div. Problem
is, I didn't put the input type=hidden name=PHPSESSID
value=aada9a6f795cb72df1ef8b8f61d2715c / in there, it's just appeared.
So. Should it be there? Is this just sessions working like they should?
I've never seen it before.
Or have I got Russian Big Boobs all over again :-)

Oh, I just put the site onto a different server on a different host and ..
I've taken another look, I did get the PHPSESSID thing inserted, so I
guess it's standard stuff.
Looks like someone may have manipulated your pages to make them 
vulnerable to session fixation attacks. This is where they'll define a 
preset PHPSESSID that'll be used when you start your session on the next 
page. The PHPSESSID is supposed to be unique and hard to guess, but 
using this method, now they'll know what the ID is and it'll be easy for 
them to craft a session cookie with the same value and take over your 
session.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] calling php function

2004-04-23 Thread John W. Holmes
From: T UmaShankari [EMAIL PROTECTED]

  Is it possible to call php function in the onclick event ?

No. Please do research on the difference between server side and client
side code. Report back to us when finished.

---John Holmes...

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



Re: [PHP] OK SQL experts...

2004-04-23 Thread John W. Holmes
From: Brian Dunning [EMAIL PROTECTED]

 I STFW and RTFM and I still can't figure out why this returns a 1064 
 parse error:
 
 SELECT * FROM 'my_table' WHERE ('field_1' LIKE '%$keyword%' OR 
 'field_2' LIKE '%$keyword%' OR 'field_3' LIKE '%$keyword%') AND 
 'status' = 'active';

Use backticks around table and column names, not single quotes. 

---John Holmes...

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



Re: [PHP] OK SQL experts...

2004-04-23 Thread John W. Holmes
From: Brian Dunning [EMAIL PROTECTED]
 My error. Here is the actual return:

 You have an error in your SQL syntax. Check the manual that corresponds
 to your MySQL server version for the right syntax to use near
 ''my_table' WHERE ('field_1' LIKE '%custom%' OR 'field_

 I am searching for the word custom, which I put in at least one of
 the fields in several records, so the search SHOULD find something.

Take out the single quotes around your table name! If you must, use
backticks, but even they aren't necessary. Then tell us what the new error
is.

---John Holmes...

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



Re: [PHP] Creating an assoc array from two arrays

2004-04-23 Thread John W. Holmes
From: Alex Hogan [EMAIL PROTECTED]
 I am looking through the manual and I think I may be blind or something,
but
 how can I create an associative array from two arrays.
 What I have is two arrays that look like this;

 Array1([0]=Spider, [1]=Monkey, [2]=Cards)
 Array2([0]=26.3, [1]=0.65, [2]=62.07)

 I want to combine them into;

 ArrayCombined([Spider]=26.3, [Monkey]=0.65, [Cards]=62.07)

 So I can compare it to a third array.

foreach($array1 as $key = $value)
{ $arraycombined[$value] = $array2[$key]; }

---John Holmes...

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



Re: [PHP] PHP vs PERL?

2004-04-22 Thread John W. Holmes
From: [EMAIL PROTECTED]

 What would be the technical arguments of PHP vs. PERL?

Depends if you catholic or not.

Use what you know.

---John Holmes...

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



Re: [PHP] install IIS ISAPI

2004-04-22 Thread John W. Holmes
From: Vincent DUPONT [EMAIL PROTECTED]

 I use to install PHP under IIS as a ISAPI module. So I
 add a ISAPI filter and define a new App mapping in 'configure'

 When looking at the documentation (see
http://be.php.net/manual/en/install.iis.php,
 Windows NT/2000/XP and IIS 4 or  newer) I can read :
 If you don't want to perform HTTP Authentication using PHP,
 you can (and should) skip this step. Under ISAPI Filters, add
 a new ISAPI filter. Use PHP as the filter name, and supply a path to the
php4isapi.dll.

 If I understand well, we should skip this step whe possible.
 I don't use HTTP authentcation, but I always add a ISAPI filter
 to my IIS config. Why should we avoid this??

 I tried to remove the ISAPI filter and restart IIS. Everything seems Ok

I've always wondered why the docs recommend to skip this step and have
commented on it in the past. I don't use HTTP Authentication, either, but
I've never gotten PHP to work under IIS without adding an ISAPI filter.

---John Holmes...

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



Re: [PHP] searching trough doc and pdf files

2004-04-22 Thread John W. Holmes
From: Arthur Radulescu [EMAIL PROTECTED]

 I need to search on the disk trough doc and pdf files. What would you
 suggest me to use for reading and indexing those kind of files?

I've heard of some doc-html/text and pdf-html/text converters. You could
convert them to that format (since you're just after the text, right?), and
then search them that way. Might be able to use COM if you're on a Windows
system, also.

---John Holmes...

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



Re: [PHP] Adding includes to files

2004-04-22 Thread John W. Holmes
From: Robert Sossomon [EMAIL PROTECTED]

 I need to add PHP calls to include a file to each page as it is
 generated, the only thing is I can't get the includes to come through
 correctly:
 
 ! Code
$display_block .= ?php include(\nav/top_nav.html\); ?;
$display_block .= ?php include(\nav/side_nav.html\); ?;
 ! End Code
 
 At the end of the generation I write $display_block to a file as

You can use output buffering:

ob_start();
include(nav/top_nav.html); 
include(nav/side_nav.html); 
$display_block = ob_get_contents();
ob_end_clean();

---John Holmes...

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



Re: [PHP] Mathematical expression calculation function?

2004-04-22 Thread John W. Holmes
From: Enfors Christer [EMAIL PROTECTED]

 Hi. I need a function that takes a mathematical expression
 in the form of a string, and calculates the result. PHP itself
 doesn't seem to provide one. I need something which can
 handle strings like:

   10*73.2+3-(4*358.2874)/352

$str = 10*73.2+3-(4*358.2874)/352;
eval('$result = ' . $str . ';');
echo $result;

 ... and so on. If it handles functions (like cos(), pow(),
 exp()) too, then that would be great.

That will. Depending on what $str is coming from, make sure you're
validating it somewhat so there's not any malicious PHP code injected (for
example $str = 'file_get_contents(secretfile.txt)' )

---John Holmes...

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



Re: [PHP] A to Z incremental

2004-04-22 Thread John W. Holmes
From: Paul [EMAIL PROTECTED]

 ?php
 for($i='A';$i='Z';$i++){  echo $i.' | ';  }
 ?

 The output is:
 A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S
| T | U | V | W | X | Y | Z |
  AA | AB | AC |
  ...
   YX | YY | YZ |

 where is should display only letters from A to Z.
 Why is that?

'A' is less than 'Z' when we're talking about strings. Same as '1000' is
less than '2' when compared as strings. Doesn't really answer why, but
that's just how it is. :)

---John Holmes...

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



Re: [PHP] regular expressions php/perl/actionscript

2004-04-22 Thread John W. Holmes
From: Gabino Travassos [EMAIL PROTECTED]

 I'm wondering if Regular Expressions are the same in Perl and PHP (and
 possibly Actionscript)? They look the same and smell the same, but if I
see
 a book in a store for Perl Regular Expressions that's $10 cheaper than the
 PHP one (is there one?), then is it the same thing?

The regular expressions used in the preg_* functions closely resembles
Perl. The basic syntax is the same. The regular expressions used in the
ereg_* functions are POSIX-Extended.

http://us2.php.net/manual/en/ref.pcre.php (Perl-compatible)
http://us2.php.net/manual/en/ref.regex.php (POSIX Extended)

---John Holmes...

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



Re: [PHP] What's wrong with this IF statement?

2004-04-22 Thread John W. Holmes
From: Robert Sossomon [EMAIL PROTECTED]

   if ($cat_id != 53 || $cat_id != 54 || $cat_id != 55 || $cat_id
 != 117 || $cat_id != 118 || $cat_id != 74)

Okay, if $cat_id is 53, this will work out to:

if(FALSE || TRUE || TRUE || TRUE || TRUE || TRUE)

which results in TRUE overall. 

You want  instead of ||

if ($cat_id != 53  $cat_id != 54  $cat_id != 55  $cat_id
!= 117  $cat_id != 118  $cat_id != 74)

which results in

if(FALSE  TRUE  TRUE  TRUE  TRUE  TRUE)

which results in FALSE overall.

---John Holmes...

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



Re: [PHP] Conditional Functions

2004-04-22 Thread John W. Holmes
From: Anguz [EMAIL PROTECTED]

 So I thought that maybe I could only define the needed ones in each
 case, although there's more in the include file. Example:

 if ($in_array('Hello', $functionArray))
 {
 function Hello()
 {
 echo 'Hello';
 }
 }

 I understand that the whole php file will be parsed, or does the parser
 skip the whole block inside the if when the condition is not met? But
 even if it is parsed, if the condition is not met, I believe that the
 function won't be defined, so I assume this would at least save RAM or
 something, right? Or not at all?

All your code is still going to be parsed. The only way you're going to
save anything is if you have conditional include() calls and only include
external files based upon what you need. For example, instead of loading
functions1.php and functions2.php, just load one or the other based upon
what action is being performed.

If you can't divide your functions up like that, then there's not much you
can save, just include the whole file. The parsing of the include files /
functions is probably going to be minimal compared to the actual execution
of the code, anyhow.

---John Holmes...

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



Re: [PHP] Escape problems...why?

2004-04-22 Thread John W. Holmes
Ryan A wrote:

For example this insert statement:
insert into test_ing values('a','a','a','a')
becomes:
insert into test_ing values (\'a\',\'a\',\'a\',\'a\')
I immediatly suspected magic_quotes but checked (via phpinfo) and see that
magic_quotes are off, as a safety precaution I even have
set_magic_quotes_runtime(0) in the config.php file...
I did see that magic_quotes_gpc is on, and then went to the PHP online
manual and it says this cant be fixed during runtime...? is this the
problem? if so how to fix it?
_runtime() applies to data coming _out_ of a database within your 
script. Answer is go turn magic_quotes_gpc OFF or use stripslashes() on 
the data.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Re: lt;buttongt; tag

2004-04-20 Thread John W. Holmes
From: Richard Lewis [EMAIL PROTECTED]

 In all fairness to IE, it WILL send the value of each button - but PHP
 cannot distinguish between them all because you have given them all
 the same name! :)
 
 RL Does input type='submit'... allow this sort of functionality?
 
 If it has a unique name, sure:
 
 input type=submit name=something-unique

 So what if I want to know which button was pressed to submit the form?

 At the moment I have:

 switch ($_POST['submit'])
 {
 case edit: ...
 case new: ...
 }

You can have multiple submit buttons, each one just needs to have a unique
name or value.

input type=submit name=submit value=New
input type=submit name=submit value=Edit

Now, when either of those buttons are pressed, you'll end up with one
$_POST['submit'] variable that'll either have a value of New or Edit. So
you can do exactly what you want above, just be sure to match up the case
(new vs. New, etc).

You can also do it with unique names:

input type=submit name=edit_submit value=Edit this Record
input type=submit name=new_submit value=Add New Record

Now, depending upon which button was pressed, you'll either have
$_POST['edit_submit'] or $_POST['new_submit'], but not both.

if(isset($_POST['edit_submit']))
{ //do edit stuff }
elseif(isset($_POST['new_submit']))
{ //do new stuff }
etc...

---John Holmes...

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



Re: [PHP] Whats faster? text files or mysql?

2004-04-20 Thread John W. Holmes
From: Andrew Fenn [EMAIL PROTECTED]

 I have two text files with two rows of data on each
 line sperated by a tab for about 20 lines in each file.
 Would it be faster accessing this data by putting it in a
 mysql table?

Depends what you want to do with the data. If you're searching through for
specific values, summing values, grouping, etc, then you'd probably be
better off putting it in a database as they are designed for those sort of
functions.

If you're just opening and displaying the file, or looking for one simple
match, then just leave it in a file.

Don't forget about SQLite if you choose the database route, also.

---John Holmes...

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



Re: [PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-20 Thread John W. Holmes
From: Tom Rogers [EMAIL PROTECTED]
 JWH Does anyone know of a script that'll receive the results of a form,
 JWH parse the original form and substitute the user supplied data in for
the
 JWH form elements and then send an HTML email of the form?

 Here is a class I use with my template system but it is easy to modify
 it.

Thanks for the tip. This requires you know what the elements of the form
are, though. Like I said, if you know what's in the form, this whole process
is pretty trivial.

I want to take an unknown form, receive the data, then redisplay the form
with the form elements gone and the values submitted replacing them. My
personal needs incorporate sending this in an email, but that's the easy
part.

input, select and textarea elements will be easy, I think. You can
just replace the whole element with a post variable matching it's name.

$page = preg_replace('/input type=text
name=([^]+)[^]+/ie','$_POST[\'\1\']',$page);

The checkboxes and radio buttons would be a little harder.

input type=checkbox name=foo value=1
input type=checkbox name=foo value=2

I'm thinking this will take two passes. First match the names of each
checkbox or radio button. Once I have the $name, I can say

$_POST[$name][$_POST[$name]] = $_POST[$name];

resulting in

$_POST['foo']['1'] = 1

if the first checkbox was selected.

Then, do a replace

$page = preg_replace('/input type=checkbox name=([^]+)
value=([^]+)[^]+/ie','$_POST[\'\1\'][\'\2\']',$page);

Accounting for arrays would require something else and I'd obviously have to
account for extra attributes within the form elements. Anybody thing of
something that's more efficient? I'm still just brainstorming here. :)

---John Holmes...

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



Re: Re[2]: [PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-20 Thread John W. Holmes
From: Tom Rogers [EMAIL PROTECTED]

 It does not need to know the form elements, only the reserved words it
 uses and you take those out and pass them directly to the class if
 needed. It takes the variable name from the POST array and uses it with
 the value. No need to know what the input fields are called or even
 what type - checkboxes and radio groups work fine.

Okay, I see what you mean.

default:  //not a keyword
$k = ereg_replace(_, ,$k);  //get rid of _ and replace with a space
if($v == BR){  //if BR add a carriage return,used for making blank line
  $this-vars['blocks']['submit'][$x]['ifs']['break'] = 'nbsp;';
  $this-text .= \n;
}else{
  $this-vars['blocks']['submit'][$x]['vars']['name'] = $k;
  $this-vars['blocks']['submit'][$x]['vars']['value'] = $v;
  $this-text .= $k : $v\n;  //add the variable name and value to email
 }

I see what you're doing here, but it doesn't fit what I'm looking for
exactly. You just create a Key : Value list to include in the email. I want
the email to look exactly like the form, only substitute in the values
submitted by the user.

---John Holmes...

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



Re: [PHP] PHP and Perl Integration for E-Cart

2004-04-20 Thread John W. Holmes
From: Pushpinder Singh [EMAIL PROTECTED]

  We are trying to incorporate a CGI Perl based E-Cart module into
 our PHP driven site. This is because the E-Cart supplied by our
 merchant uses CGI. I want to check with all of you if its possible to
 integrate PHP with Perl.

If you're talking about integrating PHP and Perl on the same page, then no.
You can call a Perl script from PHP using virtual(), though, but it will
still be difficult to integrate them if you want communication back and
forth on the same page. If you're just talking about extra PHP pages working
with the inventory or something, then that shouldn't be an issue; just
figure out the database structure.

---John Holmes...

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



Re: [PHP] PHP and Perl Integration for E-Cart

2004-04-20 Thread John W. Holmes
From: Pushpinder Singh [EMAIL PROTECTED]

 This is the situation at hand ... we have a PHP Session based Login
 module. The user is required to login to get to the Shopping cart
 (which is provided for by the Merchant) This shopping cart is CGI /
 Perl based. So my question would be to integrate the ordering with the
 PHP Login module, so that the Perl code knows the PHP session variable.
 This ways I can keep track of the the user name/email/ order status etc.

So all you really need is for a way for Perl to read PHP session files? Or
are you using a database for sessions? I'm sure this has already been
written. The session ID is available in a cookie or from the URL. You just
need to find the right file, open it, unserialize it and create your
variables to see if the person is actually logged in or not. No cookie or
session id in the URL means they haven't logged in.

---John Holmes...

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



Re: [PHP] ADOdb SQL Updates

2004-04-20 Thread John W. Holmes
From: Gabe [EMAIL PROTECTED]

 I double checked the names.  Everything looks okay.  Another ideas?

 (access): UPDATE tblFAQ_Book SET tblFAQ_Book.fldTitle = one more test
 WHERE (tblFAQ_Book.autoBookID = 1)
 
 Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access
 Driver] Too few parameters. Expected 1., SQL state 07001 in
 SQLExecDirect in \adodb\drivers\adodb-odbc.inc.php on line 504
 07001: [Microsoft][ODBC Microsoft Access Driver] Too few parameters.
 Expected 1.

What if you just tried the following query:

UPDATE tblFAQ_Book SET fldTitle = one more test
WHERE autoBookID = 1

Does access really need the tablename.column name syntax?

---John Holmes...

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



Re: [PHP] addslashes vs. mysql_real_escape_string

2004-04-19 Thread John W. Holmes
From: Hardik Doshi [EMAIL PROTECTED]
 Currently i am using PEAR DB abstration layer. Which
 function should i use to escape the ' character? There
 are couple of functions in the PEAR DB documentation
 so i don't know which one should i use.

I don't use PEAR DB, but it looks like quoteSmart() is what I'd use.

---John Holmes...

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



Re: [PHP] How to disable browser's back- and refresh-Button

2004-04-19 Thread John W. Holmes
From: Marco Schuler [EMAIL PROTECTED]

 I want to prevent the user to use the browser's back-/refresh-button in
 my multipage registration form (as well as in other forms). How can I do
 this?

You don't. I decide when I want to go back and/or refresh, not you. You need
to program your application to handle the event when it occurs.

---John Holmes...

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



Re: [PHP] PHP and HTTP requests

2004-04-19 Thread John W. Holmes
From: Aleksei Ivanov [EMAIL PROTECTED]

 I realize it's a stupid question but I need a simple solution.. I'd
 like to get contence from script-generated webpage (I send a
 regquest via get or post method to a page and it generates a
 response page - how do get that page as a string? Get the
 source of the page). It's obvious that it cannot be shown with
 file functions. Only solution I was mentioned vas CURL package
 but I'd like to solve this with standard functions. Is it possible?

$page =
file_get_contents('http://www.domain.com/page.php?param1=value1param2=value
2');

---John Holmes...

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



[PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-19 Thread John W. Holmes
Does anyone know of a script that'll receive the results of a form, 
parse the original form and substitute the user supplied data in for the 
form elements and then send an HTML email of the form?

For a static form, this obviously isn't too hard, but it'd be ideal if 
the program was dynamic enough to work with any kind of form.

Let me know if you've heard of anything. If not... well, I guess it's 
writin' time! ;)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-19 Thread John W. Holmes
Justin French wrote:
But I guess your motivation behind starting with the HTML is so that Joe 
Average can build a form in a WYSIWYG editor without caring about 
anything else, right?
Yeah, that's the key. It'd be easy if I could just build everything from 
an XML file.

I'm thinking that if I just parsed the HTML form looking for input * 
name=* *, match the name and replace the whole thing with 
$_POST['name'] and then continue on with other form elements in a 
similar matter. Skip over buttons, image maps, etc...

Just brainstorming right now... :)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] addslashes vs. mysql_real_escape_string

2004-04-18 Thread John W. Holmes
Richard Davey wrote:

Does mysql_real_escape_string (or mysql_escape_string) do anything
extra that addslashes() doesn't? In the examples in the manual it is
just used to escape the ' character, but that is exactly what
addslashes() will do anyway.
real_escape_string() takes the current character set into consideration 
when it escapes characters. Probably 99% of the time it's going to 
behave like addslashes(), but it's still good to use it because you're 
letting the database determine what needs to be escaped rather than just 
assuming it's only the characters covered by addslashes().

Is mysql_real_escape_string tolerant of magic quotes? i.e. will you
end up with double-quoted strings like: it\\'s a lovely day if you
call it too many times?
Yes, you'll end up with extra backslashes. If you ever see it\'s a 
lovely day in your database, then you're escaping the string more than 
once. You shouldn't see escape characters in your database or have to 
stripslashes() anything coming out of your database (unless you have 
magic_quotes_runtime() enabled).

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] why doesn't this work ?

2004-04-17 Thread John W. Holmes
Pooya Eslami wrote:
If I put the following script in a .php file it would work but if I put it
in an .html file doesn't work, why? script tag is only used in .html file.
You web server determines whether or not to look for PHP in a file based 
upon its extension. You must set up your web server to look for PHP code 
in .html files.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] why doesn't this work ?

2004-04-17 Thread John W. Holmes
Daniel Clark wrote:

I should have also said:

Because it's missing the ?php and ? tags, the 
 web server isn't going to run the code, but pass
 it back to the client browser.
You are right, but not for the reason you think. script language=php 
is a valid way of starting PHP mode.

http://us2.php.net/manual/en/language.basic-syntax.php

Because the file extension is .html, though, the PHP engine will not 
parse any of the PHP in the file, though.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] why doesn't this work ?

2004-04-17 Thread John W. Holmes
Pooya Eslami wrote:

I took out the scrip tags and put in ?php in the beginning and ?  at the
end, but it returns this:
$file
; } } closedir($handle); } echo 
; ?
Any ideas how to fix this?
Use a .php extension on your file. Or you can ask your hosting company 
to have .html files processed as PHP, but they won't.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Unwanted e-mails

2004-04-16 Thread John W. Holmes
From: David A. Stevens [EMAIL PROTECTED]

 I have somehow, for reasons unknown to me, gotten onto some e-mail
 list that I don't want to or need to be on. Somebody please, at all
 the above addresses, do everything possible to get me off that
 list(s).

For reasons unknown to me, you obviously ignore the bottom of every
unwanted email that you get that shows you how to unsubscribe. Here...
take my hand and together we'll send an email to
[EMAIL PROTECTED] and wait for the magic to happen
(umm.. stop holding my hand now, please).

---John Holmes...

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



Re: AW: [PHP] smarty

2004-04-16 Thread John W. Holmes
  Either we'd talk about the (dis)advantages of TE's in general
  or compare different TE's, i.e. smarty vs. pattemplate vs. xslt.

Wait a minute... are we talking about Smarty as in smarty.php.net? Because I
was thinking of something else this entire time and this completely changes
the discussion...

---John Holmes... ;)

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



Re: [PHP] Unwanted e-mails

2004-04-16 Thread John W. Holmes
From: Lester Caine [EMAIL PROTECTED]

 Does not Fing work!!
 The unsubscribe process requires you to reply to the eMail that is sent.
 THAT email is bounced for many people who are trying to unsubscribe.
 SOMEBODY NEEDS TO GET THEIR ACT TOGETHER AND FIX THE SYSTEM SO THAT WE
 C*A*N* UNSBSCRIBE !

Works for me everytime I go away for more than a couple days. Maybe you
should get a better email client.

---John Holmes...

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



Re: [PHP] sending mail with php on a linux box

2004-04-16 Thread John W. Holmes
From: Chris W [EMAIL PROTECTED]

 I'm not sure if this is a PHP, Apache, Network, or sendmail
 configuration but hopefully someone here will know.

 When I send email with PHP the from header is

 [EMAIL PROTECTED]

 I can't run a real mail server on my machine, so I want to change that
 email address to something else.  What config file do I need to look at
 to do this?

The last parameter of mail() allows you to specify additional headers.Use it
to set a From header.

$headers = From: [EMAIL PROTECTED];

mail($to,$subject,$msg,$headers);

---John Holmes...

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



Re: [PHP] Unwanted e-mails

2004-04-16 Thread John W. Holmes
From: Lester Caine [EMAIL PROTECTED]

 I am hitting reply, and EVERY php list sends a message back bouncing the
 unsubscribe message ( along with every post I have tried to make since
 XMAS - which is why I am having to use the newsgroup interface )
 This only happens on list.php.net, I have no problem with any other
 developer list I am moderator of or involved with !

I think you're just getting an autoresponder, but not from the list. Same as
every time anyone posts we get those messages from Information Desk,
Advance Credit Suisse Bank, pair-something, etc...

---John Holmes...

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



Re: [PHP] PHP editor

2004-04-15 Thread John W. Holmes
From: Chris Boget [EMAIL PROTECTED]

  function cleanFinalOutput($html){
$return = eregi_replace(\n, , $html);
$return = eregi_replace(\r, , $return);
return eregi_replace(\t, , $return);
  }

 Not to be too pedantic, but you could probably reduce the above
 to a single line function:

 function cleanFinalOutput($html){
   return eregi_replace(\n, , eregi_replace(\r, ,
eregi_replace(\t,
 , $html )));

Certainly don't need to fire up the regex engine.

return str_replace(array(\r,\n,\t),'',$html);

---John Holmes...

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



Re: [PHP] alternating row color--newbie help

2004-04-15 Thread John W. Holmes
Montagna, Dan wrote:

[snip]
I'd appreciate any hints on this...
See FAQ #38 here: http://forums.devshed.com/t25412/s.html

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Formatting phone numbers?

2004-04-15 Thread John W. Holmes
Rob Ellis wrote:
On Thu, Apr 15, 2004 at 04:31:09PM -0500, BOOT wrote:

I'm looking for a way to take a 7 digit number and put it into xxx-
format.
So basically the logic is to count 3 characters into $number and insert a
- there.
substr_replace($string, '-', 3, 0);
Won't that replace the number, though, not insert the dash?

$formatted_number = preg_replace('/^([0-9]{3})/,'\1-',$number);

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] binary data in php

2004-04-15 Thread John W. Holmes
Anthony Ritter wrote:

Greets,
Register globals are to off - however the files will not upload.
At wit's end - help please!

Thank all in advance.

TR

?
 if ($submit) {
// connect to the database
// (you may have to adjust the hostname,username or password)
MYSQL_CONNECT(localhost,root,mypass);
mysql_select_db(mydb);
 $uploadfile = $_FILES['form_data']['tmp_name'];
 $uploadname = $_FILES['form_data']['name'];
 $uploadtype = $_FILES['form_data']['type'];
 $uploaddesc = $_POST['desc'];
// Open file for binary reading ('rb')
 $tempfile = fopen($uploadfile,'rb');
  // Read the entire file into memory using PHP's
 // filesize function to get the file size.
 $filedata = fread($tempfile,filesize($uploadfile));
// Prepare for database insert by adding backslashes
 // before special characters.
 $filedata = addslashes($filedata);
// Create the SQL query.
 $sql = INSERT INTO binary_data SET
  filename = '$uploadname',
  filetype = '$uploadtype',
  description = '$uploaddesc',
  bin_data = '$filedata';
   $id= mysql_insert_id();

   print pThis file has the following Database ID: b$id/b;
   echo br;
   echo a href=\getdata.php?id=$id\Click to view file/a;
  MYSQL_CLOSE();
} else {

// else show the form to submit new data:
?
form method=post action=?php echo $PHP_SELF; ?
enctype=multipart/form-data
pFile Description:br
input type=text name=desc size=40
INPUT TYPE=hidden name=MAX_FILE_SIZE value=100
brFile to upload/store in database:br
input type=file name=form_data size=40
pinput type=submit name=submit value=submit
/form
?php
}
?
Remember... we're laughing with you, not at you. You forgot to call 
mysql_query() in your code. :)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] binary data in php

2004-04-15 Thread John W. Holmes
Anthony Ritter wrote:

I inserted the mysql_query() below

but it still doesn't upload the file nor does it throw an error.
[snip]
// Create the SQL query.
 $sql = INSERT INTO binary_data SET
  filename = '$uploadname',
  filetype = '$uploadtype',
  description = '$uploaddesc',
  bin_data = '$filedata';
 $ok = @mysql_query($sql);

 if(!$ok)die('Database error storing the file:'.mysql_error());

 $id= mysql_insert_id();

   print pThis file has the following Database ID: b$id/b;
   echo br;
   echo a href=\getdata.php?id=$id\Click to view file/a;
   MYSQL_CLOSE();
So what's the output? How do you know it's not working? If you're not 
getting an error, then your query is running and something is going in 
the database. Are you sure the problem isn't in how you're displaying 
the data?

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] preg_match

2004-04-14 Thread John W. Holmes
From: Sorry Confidential [EMAIL PROTECTED]

 I'm trying to parse a Postfix queue file to extract a few informations.
The
 Postfix queue file is a binary file.

 Here is an extract of the file, not a line, just an extract:
 N^WFrom: [EMAIL PROTECTED]N^[To: [EMAIL PROTECTED]N#Subject: Test 14
 2004-04-13  15:13N%Date: Tue, 13 Apr 2004 15:13:35 -0400

 $line is obtained with an fread

 if (preg_match('/To:.(.+)/',$line,$match)){
   print To= $match[1];
 }

 I get:
 To= [EMAIL PROTECTED]N#Subject: Test 14  2004-04-13  15:13N%Date: Tue, 13
 Apr 2004 15:13:35 -0400

 I was expecting:
 To= [EMAIL PROTECTED]

Try preg_match('/To:.([^]+)/',$line,$match)

Also, if you need to match more than one to at a time, look at
preg_match_all(). Depending on the size of the file, it may be more
efficient to read the entire file and match all of these at once.

---John Holmes...

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



Re: [PHP] function for backing up mysql

2004-04-14 Thread John W. Holmes
From: Victor Spng Arthursson [EMAIL PROTECTED]

 Wonder if anyone knows if there somewhere out there are any good
 functions that streams out data from mysql as a sql-file, like
 phpmyadmin does?

 The best would be one which I told which database and which tables to
 dump, and which directly stared streaming the data

Look on phpclasses.org. I saw a class listed in their last email notice that
did what you're looking for. I'm sure there are a couple of options there.

The easy way to do it is to just make an exec() or system() call to
mysqldump (it comes with mysql). Just call the program and capture the
output. It's the easiest way.

---John Holmes...

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



Re: [PHP] Re: smarty

2004-04-14 Thread John W. Holmes
From: pete M [EMAIL PROTECTED]

 Think everyone is missing the point..
 the whole point of smarty is to take the presentation code away from the
 logic

Correct. The point your missing is that PHP can be on both sides of the
equation. You can have PHP in your templates that only controls your
presentation and then have PHP on your backend that conducts your business
logic. Or, you can have Smarty on top of PHP to control you're presentation.
Personal preference, but don't confuse the process of separating
presentation from business logic as meaning you can't have any PHP code in
your presentation layer.

---John Holmes...

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



Re: Re[2]: [PHP] smarty

2004-04-14 Thread John W. Holmes
From: Richard Davey [EMAIL PROTECTED]

 Because you're injecting variables directly into your HTML, which some
 of the time might be ok - but what if the $row_array doesn't contain
 name ? You'll raise an Error Warning without first passing it
 through some kind of test (or function).

Only if you have error_reporting() set high. If you have a PHP templating
solution, you'd turn error_reporting() down when you included the PHP
templates so you didn't get a warning.

 You assume that the PHP short-tags are enabled (? ?) for
 echoing variables and while most the time they are, you shouldn't bank
 on it in code (incidentally, you don't need the trailing ; on the
 short-tag echos).

You're relying on web-server writable directories when you use Smarty. It's
all a trade-off.

  But what if you want to take your template and perform a bit more than
 just mere variable substitution on it? How about highlighting all
 words that match a search term, or applying logic to a display block
 based on a user status?

You can do this with output buffering and PHP functions. Smarty just
provides you a different interface.

?php start_highlight(); ?
Paragraph Text
?php end_highlight(); ?

vs.

{section type=highlight}
Paragraph Text
{/section}

Yeah, I know that's not quite the Smarty syntax, but you get the idea.
Smarty just provides an easy interface to a lot of these things. It's a
tool, like a lot of others have said. :)

---John Holmes...

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



Re: [PHP] unexpected $ in ... WTF?

2004-04-14 Thread John W. Holmes
From: Brian V Bonini [EMAIL PROTECTED]

 Parse error: parse error, unexpected $ in /foo/bar/foo.php4 on line 150
 
 146: /p
 147: ?php
 148: }
 149: include foobar.inc.php4;
 150: ?

You missed a closing bracket or quote somewhere.

---John Holmes...

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



Re: [PHP] requests per s with php and mysql queries

2004-04-12 Thread John W. Holmes
From: Merlin [EMAIL PROTECTED]

 I am trying to stress my LAMP app with MS stress tool for web
applications.
 It simulates about 100 threads.

 It looks like the LAMP app is only able to handel about 6 requests per
second :-(
 Is this normal für php with database queries?

Every application is different. You can't ask a question like this. Even if
people said Yes or No, how is that going to help you?

---John Holmes...

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



Re: [PHP] After calling a Function the Script aborts without any error :-\

2004-04-12 Thread John W. Holmes
From: Ben [EMAIL PROTECTED]

 i got a big problem. I have a script which includes some other script i
 tried include, require and require once. The problem is, if i do a
 function call to a function in one of these included files, the script
 aborts but without any error. The strange thing is, normally require
 should give an error if it can't include any file. But the files are
 accessible, error reporting is E_ALL. Some functions are callable but
 others not and still no error. the only way how i came to this was
 putting some die()s to see where 

Do you have display_errors turned on?

---John Holmes...

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



Re: [PHP] Preg_match_all problem

2004-04-12 Thread John W. Holmes
From: Jeff McKeon [EMAIL PROTECTED]

 Can anyone see why I'm getting this error message:

 Warning: No ending delimiter '^' found in
 C:\Inetpub\wwwMIS_DEV\import_mvs.inc.php on line 126

 From this line:

 if(preg_match_all(^([00])?.*$,$called,$found))

Because you do not have an ending delimiter. In fact, you don't have a
starting delimiter, either, but preg assumes you meant the ^ character to be
your delimiter.

This is explained in all of the examples in the manual, but you must
surround your regular expression by a delimiter such as the / or #
character. This is because you can include modifiers after the delimiters to
further create your regex.

if(preg_match_all(/^([00])?.*$,$called,$found))

Although I doubt that'll work like you want it since [00] matches a zero, or
another zero. It only matches one character.

 I basically have a phone bill that sometimes has the phone number
 preceeded by 00 and sometimes not.

 When it has the 00 I want to trim it with the substring command.

I wouldn't even use preg for this. Just use ltrim() or
if(substr($called,0,2)=='00')...

---John Holmes...

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



Re: [PHP] Preg_match_all problem

2004-04-12 Thread John W. Holmes
From: John W. Holmes [EMAIL PROTECTED]
 From: Jeff McKeon [EMAIL PROTECTED]

  Can anyone see why I'm getting this error message:
 
  Warning: No ending delimiter '^' found in
  C:\Inetpub\wwwMIS_DEV\import_mvs.inc.php on line 126
 
  From this line:
 
  if(preg_match_all(^([00])?.*$,$called,$found))

 Because you do not have an ending delimiter. In fact, you don't have a
 starting delimiter, either, but preg assumes you meant the ^ character to
be
 your delimiter.

 This is explained in all of the examples in the manual, but you must
 surround your regular expression by a delimiter such as the / or #
 character. This is because you can include modifiers after the delimiters
to
 further create your regex.

 if(preg_match_all(/^([00])?.*$,$called,$found))

damn... i left out the ending delimiter, too.. :)

if(preg_match_all(/^([00])?.*$/,$called,$found))

---John Holmes...

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



Re: [PHP] creating log files out of a delete statement

2004-04-11 Thread John W. Holmes
Andy B wrote:

i have a section of a website that deletes records from a mysql table...
right now all the query is is a delete statement but i need to make a log
file in this format:
current time::username who executed delete:: deleted(name of record)::delete
completed
or delete failed depending on what happened... i can do all of the log
except dont exactly know how to extract the Name field of the deleted
record before it actually gets dumped.. that way i can use it on the log...
There's no way to extract it from the DELETE. You'll have to do a SELECT 
with the same parameters that you're going to do the DELETE with. Grab 
your data with the SELECT then execute the DELETE.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


<    1   2   3   4   5   6   7   8   9   10   >