Re: [PHP] newbY prob

2003-07-23 Thread CPT John W. Holmes
From: Jennifer Goodie [EMAIL PROTECTED]
  ! am trying to count the number of items in this table. The table
  has one field in it.
 
  The code I am using is:
 
  $dbquerymeal = select COUNT(*) from mealtype;
  $resultmeal = mysql_db_query($dbname,$dbqueryshipping1);
  if(mysql_error()!=){echo mysql_error();}
  $mealcount = mysql_fetch_row($resultmeal);
  echo $mealcount;
 
  The result I am getting is:
 
  Query was empty
  Warning: mysql_fetch_row(): supplied argument is not a valid
  MySQL result resource in search.php
 
  Any suggestions?

 Where is  $dbqueryshipping1 set?  I see $bdquerymeal, but not
 $dbqueryshipping1.

Also, once you fix that, $mealcount is going to be an array. You need to
display $mealcount[0] to get the value.

---John Holmes...


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



Re: [PHP] Some SESSION Vars not Registering

2003-07-23 Thread CPT John W. Holmes
From: Jeff Stillwall [EMAIL PROTECTED]

 Now I'm (possibly) getting somewhere:

 When I modify the function to be this (notice the key name change by
adding
 s):

 function setupUserEnv ($userArray) {

 $_SESSION['loggedIn'] = 1;

 foreach($userArray as $key=$value) {
 echo Assigning $key = $valuebr;
  $_SESSION[$key.s] = $value;
 }
 }

Why not just

$_SESSION['userArray'] = $userArray;

??

Then $_SESSION['userArray']['fname'] to access the values, for example.

---John Holmes...


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



Re: [PHP] Global variable question question

2003-07-23 Thread CPT John W. Holmes
 When registered globals is set to off this does not effect the $PHP_SELF
 variable right?  In other words I should be able to call $PHP_SELF with
 out having to do this $_SERVER['PHP_SELF'], right?

No. With register_globals OFF, $PHP_SELF is not set. 

---John Holmes...

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



Re: [PHP] Search question ..

2003-07-23 Thread CPT John W. Holmes
From: Curt Zirzow [EMAIL PROTECTED]
 * Thus wrote James Hatridge ([EMAIL PROTECTED]):
  I've got a search page written for my web site. I can find the html page
I
  want by keyword. Now I need to get the title of that page in to a
variable.
  In other words I have a file name, for example Summerbulletin.html. I
now
  need to get the line title Summer 2003 /title in to a variable.
How do
  I tell html or PHP what I want? (I hope that I am understandable, I'm
still
  new at this. )
 
  Right now I output the search results in to a chart that shows
  Summerbulletin.html. What I would like to show is Summer 2003.

 preg_match('#\title\(.*)\/title\#im', $text, $matches):

I don't think you have to escape the  and  characters, do you? Also,
what's the 'm' modifier for? (I know what it does, why are you using it
here?)

Also, if there's ever a case where could have

title
My Title
/title

i.e. things spread over multiple lines, then you'll need:

preg_match('#title(.*)/title#is',$text,$matches);

or, even better (ungreedy)

preg_match('#title([^]+)/title#i',$text,$matches);

The 's' modifier will allow you to match the title even though it's over
multiple lines with the first regex example. It's not needed in the second.

---John Holmes...


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



Re: [PHP] I'm really getting annoyed with PHP

2003-07-23 Thread CPT John W. Holmes
From: Beauford.2005 [EMAIL PROTECTED]
 Yes, I'm still screwing around with this stupid redirection thing, and
 either I'm just a total idiot or there are some serious problems with
 PHP. I have now tried to do it another way and - yes - you guessed it.
 It does not work.

 I mean really, it can not be this hard to redirect a user to another
 page. If it is, then I must look into using something else as I just
 can't be wasting days and days on one minor detail that should take 30
 seconds to complete.

 If anyone has some concrete suggestion on how to get this to work It
 would be greatly appreciated. In the mean time I have given up on it as
 I am just totally pissed off at it.

Let's start over, shall we? Even I've lost track of where you are and what
you've tried. You're right, though, this isn't hard. It's being done on many
web pages out there, also, so I highly doubt it's a PHP issue. It's more
likely a BMAC issue. ;)

What the code you have right now and what isn't working?

---John Holmes...


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



Re: [PHP] Problem with MySQL Query

2003-07-23 Thread CPT John W. Holmes
Take out the plus sign... type != 'Meal Plans'

And using single quotes in your query might make things easier (no
escaping...)

$dbqueryshipping1 = select * from tempuserpurchase where
usersessionid='$User_Shopping_Id' and day='1' and type!='Meal Plans';

You don't need quotes around '1' since it's an integer, but MySQL is
forgiving.

---John Holmes...

- Original Message - 
From: Phillip Blancher [EMAIL PROTECTED]
To: PHP List [EMAIL PROTECTED]
Sent: Wednesday, July 23, 2003 5:08 PM
Subject: [PHP] Problem with MySQL Query


Problem with mySQL Query
This is the query I have:

$dbqueryshipping1 = select * from tempuserpurchase where
(usersessionid=\$User_Shopping_Id\) and day=\1\ and type!=\Meal+Plans\
;

What I want to do is to select everything from tempuserpurchase that matchs
the user session and the day, so long as type is not Meal Plans

However it is not excluding Meal Plans

Any Suggestions.

Thanks in advance,

Phil


__


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.501 / Virus Database: 299 - Release Date: 7/14/2003



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



Re: [PHP] Software Application Engineer WANTED (PHP/MySQL Guru)

2003-07-23 Thread CPT John W. Holmes
 Subject: [PHP] Software Application Engineer WANTED (PHP/MySQL Guru)

I hope there are job postings like this if/when I get out of the Army! :)

---John Holmes...

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



Re: [PHP] just looking for some opinions...

2003-07-24 Thread CPT John W. Holmes
 Let's say I have a number: 1281924

 The rules call for removing 1280+, meaning remove 128 and all 0's that
 come after it, until you run into another number.

 In the end, it would leave 1924, and everything else on the beginning
would
 be gone.

$new_number = preg_replace('/^1280+/','',$number);

---John Holmes...


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



Re: [PHP] Rewrite img and a tags.

2003-07-25 Thread CPT John W. Holmes
 How can I easiest rewrite A and IMG tags? I'm fetching a page with
 fsockopen() and I need to rewrite these tags before sending it on to a
user.

 My own theory is that it's made with Regular Expressions. I just don't
 know these myself.

If you're writing one of those anonymous browsing programs where
everything is requested through PHP and shown on your site with the links
rewritten, there's already one written on phpclasses.org. See how they do
it.

---John Holmes...


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



Re: [PHP] Debugging a Session Problem

2003-07-25 Thread CPT John W. Holmes
From: Lee Stewart [EMAIL PROTECTED]
 I'm moving an application that I'm in the trying to move to a new
 platform.   It was running fine on an older Linux platform with PHP
 4.0.3 and Apache 1.3.14.  The new platform is also Linux, with PHP 4.2.2
 and Apache 1.2.26 -- with register_globals on.  (I just upgraded it from
 4.2.2.36 to 4.2.2.69 which is the latest rpm on SuSE's site, with no
 change in the problem.)

 The symptom is that when I attempt to save a session variable, it
 creates the session file in /tmp, but with a zero length - no variable
 names or values stored.  (/tmp is globally read/write)  This happens not
 only with the application I'm moving, but also with the world's
 simplest global test pages below.

 [page1.php]
 ?
 session_start();
 session_register('test');
 $test='foobar';
 header('Location: page2.php');
 ?

Seem to remember something about starting a session and then redirecting
with header causing trouble. Try using session_write_close() before you
redirect.

---John Holmes...


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



Re: [PHP] file_put_contents()?

2003-07-25 Thread CPT John W. Holmes
 Another stupid newbie question...(btw, is there a list more geared towards
 the newbies?)

Yes, it's called the manual. 

 Is the file_put_contents() function not available in PHP 4.3.2?

Seriously: www.php.net/file_put_contents

---John Holmes...

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



Re: [PHP] variable in function parameter

2003-07-28 Thread CPT John W. Holmes
 * Thus wrote 386-DX ([EMAIL PROTECTED]):
  Hello. Let's say I have something like this:
 
  function aa($test) {
  $a = 8;
  echo $test;
  }
 
  $a = 2;
  aa(a is . ($a5?greater:equal to or less).  than 5.);

 http://php.net/eval

No... you need to make $a global within the function for that change to
affect $a outside the function

function (...)
{
  global $a;
  $a = 8;

(can maybe do that in one operation, try it and see)

---John Holmes...


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



Re: [PHP] Store array as Session Variable

2003-07-28 Thread CPT John W. Holmes
$details is an array (just like $company_name was). Try to view
print_r($details); and see what you get.

---John Holmes...

- Original Message - 
From: Pushpinder Singh Garcha [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, July 28, 2003 3:18 PM
Subject: [PHP] Store array as Session Variable


hello All,

  I am trying to store an array as a session variable.

while ($row = mysql_fetch_array($result))
{
if ( !is_array($company_name) ) $company_name = array();
   array_push($company_name, $row['company']);

// try to register session variable
 $_SESSION['link'] = $company_name;

}


Now when I try to access this session variable in another file...I am
getting a junk value.I am not sure if I am getting this right.

$details = $_SESSION['link'];
  echo LINK: .$details.br;


Can some one fill me in on this. Appreciate it !  Thanks in advance.

--Pushpinder Singh


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



Re: [PHP] Store array as Session Variable

2003-07-28 Thread CPT John W. Holmes
  I am able to see the contents of the $company_name array. The next
 part involves storing this as a session variable.

 I am trying to link this page to another search page using the  a
 href=\full-profile.php?name=.$row['company']. \--Link--/a

If you're passing the company name in the URL, why are you adding the entire
array to the session? You can just use $_GET['name'] to get the name of the
company that was clicked on...

---John Holmes...


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



Re: [PHP] learning php - problem already

2003-07-29 Thread CPT John W. Holmes
 Hello everyone,
 Am new to php and have run into a problem while reading my book... can
anybody tell me what does this mean:

Hi... let's see who gets this one first... :)

 foreach($invoice as $number = $pppno)

$invoice is an array. foreach() is going to loop through that array one
element at a time. For each element, it'll take the key and place it into
$number. It will take the value of the element and place it in $pppno. So,
if you had array('one','two'), the first element is one with a key of zero
(default). So, the first time through the loop, $number will be zero and
$pppno will be one. The next time through the loop, $number will be one
and $pppno will be two.

 and also this:

 while(list($k,$v,) = each($a))

Same kind of thing here, just a different method. each() loops through an
array. For each element, it'll return an array consisting of the key and
value. list() takes that array and assigns the first element of the array to
$k and the second to $v. The final while() just loops through everything
until all of the elements of $a have been run through. So, if we have our
array('one','two); again, each() will take the first element, one, and
pass an array consisting of the key, zero, and the value, one to list().
list() will assign zero to $k and one to $v.

 I do understand for loops and while loops but this is a bit confusing...do
you haev any links I can read up on these?

Hope that helps. That was as much of a test for me in seeing if I could
explain it, so tell me how I did! :)

---John Holmes...


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



Re: [PHP] Files created by PHP/Apache

2003-07-30 Thread CPT John W. Holmes
 I've got a problem with preconfigured server (Apache 1.3/MySQL 3/PHP 4):

 Files and directories created by a PHP script are always owned by the
apache
 user and apache group. But the script itself is inside of a virtualhost
 which has another user and group (web2 / ftponly)!

 So in fact the script has to run with the rights of the user web2??
Perhaps
 it does, but files/dirs are create with owner apache.

PHP runs as a module inside of apache, so any files it creates are owned by
the Apache user. That's the way it works.

If you run PHP as a CGI, this does not happen. Or use FTP to make files.

---John Holmes...


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



Re: [PHP] cookies on localhost WinXP

2003-07-30 Thread CPT John W. Holmes
 I have PHP/Apache/MySQL installed on my WinXP laptop.  I do this so that I
 can write programs when not connected to the Internet (like when
 traveling).  I am trying to set a cookie from the http://localhost site on
 my computer and it doesn't get set.  Does this sound like something wrong
 in my php.ini file or my browsers?  The program works fine on my
 RedHat/Apache/PHP/MySQL server.

HOW are you trying to set it? What browser are you using? How do you know
it's not set?

---John Holmes...


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



Re: [PHP] downloading a file using headers

2003-07-30 Thread CPT John W. Holmes
 I have a page that queries the database then uses the data to build an
 excel spreasheet.  THat spreadsheet is downloaded according to info in the
 headers.  My manager wants to put the page inside of another HTML page to
 make it prettier, but then it breaks because headers are already written
 (it's included in the other HTML page).  It works fine on it's own, but
 he really wants it in that page.  He wants to know if there is a
 way to trick it into working.

Just set a flag on whether you send the headers or not. Have it default to
sending them...

if(!isset($somevariable))
{ header(...); }

---John Holmes...


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



Re: [PHP] cookies on localhost WinXP

2003-07-30 Thread CPT John W. Holmes
 h.  This seemed to set the cookie just fine.  Does this mean that
 either localhost in the browser or Apache/PHP on a windows box has to set
 the cookie differently than on RedHat/Apache/PHP?  I am going on vacation
 next week and need to keep working on a project that is working fine on
the
 RedHat server, but not on my localhost.  Basically, by this test, it
sounds
 like on my laptop I have to use a
 header('Set-Cookie: ...);
 instead of
 setcookie (coach_access[login_id], coach,0,/,$cookhost);
 If so, I can't seem to get it to work with coach_access[login_id] as the
 cookie name.

That's because it's a bad name. To retrieve that value, you'd have to use

$_COOKIE['coach_access[login_id]'] and that's IF the client let's you set a
cookie with that name.

If you're trying to put an array into a cookie, use serialize().

---John Holmes...


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



Re: [PHP] cookies on localhost WinXP

2003-07-30 Thread CPT John W. Holmes
From: Steve Buehler [EMAIL PROTECTED]
 hm.  Looks like on my localhost I can't seta cookie like this:
 setcookie (coach_access[login_id], coach,0,/,$cookhost);
 if I change it to just:
 setcookie (coach_access_login_id, coach,0,/,$cookhost);
 it will work.  But then my script won't work without a lot of re-writing
 because it uses $coach_access[login_id] instead.  Any help here?  Am I
just
 doing something wrong?  I can't set it with the following either.
 header('Set-Cookie: coach_access[login_id]=coach');
 But can as:
 header('Set-Cookie: coach_access_login_id_=coach');
 but again, I would have to re-write a lot of script.

You'd be better of if you re-wrote your code to make it correct, but you
could just put:

$coach_access['login_id'] = $_COOKIE['coach_access[login_id]'];

Please don't tell us that you're storing login IDs in a cookie and actually
depending upon them for anything??

---John Holmes...


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



Re: [PHP] learning php - problem already

2003-07-31 Thread CPT John W. Holmes
From: Ford, Mike [LSS] [EMAIL PROTECTED]
 From: John W. Holmes [mailto:[EMAIL PROTECTED]
  The four element array will be
  1 = 'one'
  value = 'one'
  0 = 0
  key = 0

 OK, some more red pen coming along

Since we're whipping them out (red pens that is)

 The four-element array would actually be:

   0=0
   1='one'
   'key'=0
   'value'='one'

Nope. Try this example from the manual and you'll see that you get the order
I gave

$foo = array (bob, fred, jussi, jouni, egon, marliese);
$bar = each ($foo);
print_r($bar);

The order is pretty irrelevant, though.

list($k, $v, $key, $value) = each($a);

 you would, in this case, now have $k==0, $v=='one', $key==0,
$value=='one'.

Nope.. try that and you'll get two notices about undefined offsets at 3 and
2. $key and $value will not have any value at all.

Not that this really matters, but since this is fun to argue about...

$a = array('a' = 'abc');

Since we know that each($a) will return what I gave above, you basically
have this:

list($k,$v,$key,$value) = array(1='abc', 'value'='abc', 0='a',
'key'='a');

So, how this works is that list starts with $value. $value is at position
number four, so since arrays start at zero, it's going to look in the array
that was passed for an element at [3]. Since there is no [3] in the passed
array, you get a NOTICE about undefined offset.

Next it moves on to $key and looks for element [2]. Again you get a warning
since there is no element [2] in the passed array.

Next is $v and list is looking for [1]. Since [1] does exist and has a value
of 'abc', now $v = 'abc'

Last is $k and [0] and you get $k = 'a'.

That's how it works. :)

That's why this code:

list($a, $b, $c, $d) = array(4='four', 3='three', 2='two', 1='one',
0='zero');
echo $a, $b, $c, $d;

gives:

zero, one, two, three

as the result, even though you passed a five element array in reverse order.

---John Holmes...


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



Re: [PHP] Where am i screwing up?

2003-07-31 Thread CPT John W. Holmes
From: Ryan A [EMAIL PROTECTED]
 I am just screwing around and getting used to arrays with a foreach
thanks
 to Michael,Jan and Evan from this list and have run into problems.

 My requirment is pretty simple (code is below too)
 1)unset all the sessions that might have been set with reference to the
 hardcoded array ($vars)
 2)if any checkboxes have been set from the previous form then set that
 session
 needless to say, its not working, am too new at this to know where my
fault
 is so any help is greatly appreciated.

 I have even added a few comments as to what i was thinkingtell me if i
 was wrong.

 **Start code
 ?php
 $vars = Array('noPlatform','noPrice','noSfee','noSpace');  // this
 corresponds to the name= of each checkbox

 foreach ($vars as $key) // clear all previous sessions
  {
  if(isset($_SESSION['$key']))
  {
 unset($_SESSION['$key']);
  }
  }
 echo done1; //just checking program execution

 foreach ( $vars as $ ) // if any checkboxes were checked create a
 session for them
 {
  ${$} = ( isset($_POST[$]) ? 1 : 0 );

  if($==1)
   {
$_SESSION[$];
echo $; //getting no output from here...I just put it here for
 testing
   }
 }
 echo done2; //just checking program execution
 ?

 End code

How about you name your checkboxes as:

name=setting[xx]

where xx is from your $vars array above. You'll end up with

name=setting[noPlatform] value=1
name=setting[noPrice] value=1
etc...

Now, you'll have $_POST['setting'] that'll contain the checked boxes.

To put those in session:

$_SESSION['setting'] = $_POST['setting'];

To see which boxes were checked...

$checked = array_keys($_POST['setting']);
or
$checked = array_keys($_SESSION['setting']);

$checked now an array similar to your $vars above but it only contains the
values that were checked.

To find out which checkboxes were NOT checked, you could use:

$not_checked = array_diff($vars,$checked);

Easy, eh?? Hope that helps.

---John Holmes...


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



Re: [PHP] Re: php path statement appears on my webpages

2003-07-31 Thread CPT John W. Holmes
 Thanks, but if I leave off this line then I get an error when I try and
 view my pages.

What kind of error, exactly?

You need to determine if you're running PHP as a module or CGI. 

---John Holmes...

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



Re: [PHP] session header issue

2003-07-31 Thread CPT John W. Holmes
From: Ow Mun Heng [EMAIL PROTECTED]


 snip
 The Location: header requires a correctly formed URL, ie http://...
 /snip

 I'm running fine using only Location:home.php on Mozilla  IE 6

 maybe I should change.

Please see my previous emails on the difference between works and
right...

---John Holmes...


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



Re: [PHP] Formatted text from mySQL DB

2003-08-05 Thread CPT John W. Holmes
From: PHPSpooky [EMAIL PROTECTED]
 When I create any field and let data be sent into my mySQL DB through
 it.. it goes ok. But when I retrieve it.. the data comes completely
 unformatted.

Ah, this question again. Has it been four days already?

HTML does not render new lines. Have a look at the source code of your page
and you'll see that the text is indeed on separate lines. HTML only
understands something like br /, though, to go to a new line. So, you need
to replace the new line characters with HTML breaks in order to maintain
appearance.

www.php.net/nl2br

---John Holmes...


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



Re: [PHP] PHP/JavaScript/HTML

2003-08-05 Thread CPT John W. Holmes
From: Mauricio [EMAIL PROTECTED]
 I wrote a JavaScript to set the values of a Select html object by client
 side. The values are copied from another Select that I create getting the
 values from the database. After the user set the values he/she wants to
add
 it in another form, for example, then press submit button, the values of
the
 user Select object doesn't appears on the next page. What can I do to
get
 the user selected values in the another page?

Well, if I understand that correctly, you need to use Javascript to select
all of the options that the user selected to add to the second select box.
If they aren't selected, then they won't be passed to the next page.

---John Holmes...


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



Re: [PHP] Repopulating forms

2003-08-05 Thread CPT John W. Holmes
From: Gerard L Petersen [EMAIL PROTECTED]
 My code looks like this.

 ?PHP
 $test = gerard's name is \gerard\;
 echo $test.br;
 echo 'input type=text name=test2 value='.$test.'br';
 ?

Just like HTML doesn't render newlines, it also doesn't understand using the
\ character as an escape character. You are creating this:

input type=text name=test2 value=gerard's name is gerard

So, HTML takes the first bit between double quotes and ignores the rest as a
unknown attribute.

Run htmlentities() on $test before putting it in the INPUT element to change
the quotes to HTML entities.

---John Holmes...


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



Re: [PHP] PHP/JavaScript/HTML

2003-08-05 Thread CPT John W. Holmes
From: Mauricio [EMAIL PROTECTED]
 On the Address Bar I can see: index.php?slcAdd=1slcAdd=2slcAdd=3
 But when I get the value using $HTTP_GET_VARS['slcAdd']; it returns just
the
 last value. What can I do to get them all?

Name your select box as slcAdd[] and you'll have all of the values in an
array.

---John Holmes...


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



Re: [PHP] Parse error not understood

2003-08-07 Thread CPT John W. Holmes
From: Chris Blake [EMAIL PROTECTED]
[snip]
 //If Delete User is selected--
 if ( $_REQUEST['useroption'] == 'delete')
 {
[snip]
 No matter which option I select I get the following output :
 --
 Parse error: parse error, unexpected $ in
 /var/www/html/Sessions/userman.php on line 83
 
 Line 83 is '?'..

You're missing a closing brace for the above IF condition...

---John Holmes...

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



Re: [PHP] error: cannot redeclare ()

2003-08-07 Thread CPT John W. Holmes
From: Martin Towell [EMAIL PROTECTED]
 I'm getting the following error:

 PHP Fatal error:  Cannot redeclare () (previously declared in
 /path/to/file/functions.inc:19) in /path/to/file/functions.inc on line 0

 Anyone have any ideas how a no-name function could be generated?
 Line 19 contains:
 function idb_exec_deadlock($sql,$count=0)

Make sure you're not including/requiring functions.inc more than once. This
is usually what causes these kind of errors.

Also, I hope you are denying access to .inc files on your server, otherwise
your PHP code will be served up as plain text.

---John Holmes...


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



Re: [PHP] Correct Coding

2003-08-07 Thread CPT John W. Holmes
From: Martin Peck [EMAIL PROTECTED]
   That can generate an error if $Task was never assigned a value.
  
 
  could you not do
 
  if(@$Task == Add ){do something }
 
  to suppress the error of the variable not being set?

 I have never seen php give an error if $Task is not set to anything.  I
 would have said that

It would give an error if you have your error reporting set accordingly.
Search the archives for the difference between works and right (or the
next issue of PHP|Architect) :)

---John Holmes...


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



Re: [PHP] Hitler and Recent Threads

2003-08-07 Thread CPT John W. Holmes
From: Mark [EMAIL PROTECTED]

 And as they say, Never argue with a fool. People will
 not be able to tell the differnce.

I thought it was Never argue with an idiot. They drag you down to their
level and beat you with experience

:)

---John Holmes...


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



Re: [PHP] Downloding files once

2003-08-07 Thread CPT John W. Holmes
From: Boaz Yahav [EMAIL PROTECTED]
 
 Can you fake a referrer by say, using fsockopen() and sending your
 own headers?

Yep.

---John Holmes...


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



[PHP] Re: [PHP-DB] Sorting issue

2003-08-08 Thread CPT John W. Holmes
Jeff [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Why would a mysql db think that 55 was greater than 14000.

 I have several headings that display sql data under them, when you click
on
 the heading, it sorts that section (descending/ascending), but it only
seems
 to be looking at the first two numbers in the one heading.   Is there a
 command that forces it to look at the entire record before sorting it?

Because 55 is greater than 14000... i.e. you're sorting the values as
strings, not integers.

---John Holmes...


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



Re: [PHP] setting function variables

2003-08-09 Thread CPT John W. Holmes
From: Mark [EMAIL PROTECTED]
 I seem to learn something new every time you or Jennifer post (many
 others as well). I never knew about variable functions. Cool!

You're welcome. I wouldn't recommend that solution exactly (an abstraction
class would be better), but the functions do come in handy.

For example, I use variable function in one of my validation classes. I have
a main method called check() that is passed a type and a value. The
type must match a method in the class. The check() method does some
default checking and then passes the $value to the $type() method for
further checking...

class Validate
{
  function check($type,$value)
  {
if($empty($value))
{ return FALSE; }
if(method_exists($this,$type))
{ $retval = $this-$type($value); }
return $retval;
  }

  function number($value)
  {
if(preg_match('/[^0-9]/',$value))
{ return FALSE; }
else
{ return $value; }
  }
}

Where number is one of the types that'll be validated.

$val = new Validate;

$val-check('number',$_POST['somevalue']);
$val-check('date',$_POST['somedate']);
$val-check('phone',$_POST['phone_number']);
etc...

Where you'd have a phone() and date() method in the Validate class... I
think that's the only place I've used variable-functions... or
variable-methods, rather. :)

---John Holmes...


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



Re: [PHP] htmlspecialchars() and HTML code

2003-08-10 Thread CPT John W. Holmes
From: Thaddeus J. Quintin [EMAIL PROTECTED]
 I'm working on a site where users have the option to type HTML code into
 a textarea, or upload HTML code from a local file which is then
 displayed in the text area.

 The obvious problem is that an uploaded file that contains a closing tag
 for a textarea can wreak havoc and eat up the rest of the page.  So, in
 order to get it to display properly, I called htmlspecialchars() on the
 string and that works fine.

 After any editing has been done, I can convert the text back using
 html_entity_decode().  This seems to be a decent solution to the problem.

 However, if the user has included htmlentities in their code, won't
 these get converted when I call the decode function?  Even something
 simple like using a '' symbol for a little arrow.  This would need to
 remain a 'lt;' and not get converted when html_entity_decode() is called.

You should not have to call html_entity_decode() at all. You encode the text
to get it to show in the text area. When the form is submitted, you get the
text exactly as it appears in the textarea. in other words, without the html
entities.

Try this:

textarea name=textThis is lt;somegt; text/textarea

If you submit that text and then print $_REQUEST['text'], you'll see that
you have

This is some text

---John Holmes...


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



Re: [PHP] how do i get assosciative name in foreach

2003-08-10 Thread CPT John W. Holmes
From: Dan Anderson [EMAIL PROTECTED]
 I want to do:
 
 ?php
 
 $array['element1'] = 'element1';
 $array['element2'] = 'element2';
 
 foreach ($array as $element)
 {
   // assuming get_assoc gets the assosciative name
   if (get_assoc($element) == 'element1')
 {get_assoc($element) do_something(); }
   elseif ( == 'element1')
 { do_somethingelse(); }
 }
 
 ?

Refer to the manual:

foreach($array as $key = $value)

So...

foreach($array as $key = $element)
{
  if($key == 'element1' ...
  if($key == 'element2' ...

---John Holmes...

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



Re: [PHP] Stop neurotic posting

2003-08-10 Thread CPT John W. Holmes
Honestly, if you people ignored the stupid responses as much as you want us
to ignore the stupid questions... we wouldn't be having this discussion.

---John Holmes...

- Original Message - 
From: Nicholas Robinson [EMAIL PROTECTED]
To: andu [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Wednesday, August 06, 2003 10:55 AM
Subject: Re: [PHP] Stop neurotic posting


Andu's right. I've left several lists in the past, not because of people
listing questions where they should have read the manual first, but because
I
couldn't stand the sad b**ds who get their kicks by belittling people
with less knowledge but more manners than themselves.

I've actually learned quite a few useful things from questions in the past
couple of weeks since I joined this list that have obviously reappeared
several times. Now, I could spend hours trawling the archives to see if
there's anything of interest, but I don't really have the time - and in any
event they're often things I wouldn't have thought about looking up anyway.

So, keep the questions coming.

Nick

On Wednesday 06 Aug 2003 5:31 am, andu wrote:
 This is a very busy list, over 100 message in a quiet day and most people
 are helpful and decent, don't mind reading and learning. Unfortunately
 there are some who mostly post stuff like 'read the manual' and other shit
 like that. Stuffing e-mailboxes with such garbage day after day doesn't do
 anybody any good even if the manual is  not being read as much as it
should
 be. Is it too difficult to not answer the post at all if you disagree with
 the content?


 Andu


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


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



Re: [PHP] Validate The Last Day of Month with server's clock????

2003-08-14 Thread CPT John W. Holmes
From: Nicholas Robinson [EMAIL PROTECTED]

 The 'usual' trick is to set the date to the first day of the month after
the
 one you want and then subtract one day.

Along those same lines, this works:


?php

$month = 12;
$year = 2003;

$last_day_of_month = mktime(12,0,0,$month+1,0,$year);

echo date('m/d/Y',$last_day_of_month);

?

---John Holmes...


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



Re: [PHP] Config files

2003-08-14 Thread CPT John W. Holmes
From: Hardik Doshi [EMAIL PROTECTED]
 I have following options for working with the
 configuration files with the relatively large web
 application.

 1. Configuration variables using the DEFINE.

 2. Array - Each configuration variable as an array
 element.

 3. PHP.INI like config files.

A combination of #3 and #2. Store the data in a php.ini-style config file
and use parse_ini_file() to read it into an array.

You could even merge the array into the $_SERVER (or any other superglobal)
array so that your config vars are available in functions without having to
make anything global.

---John Holmes...


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



Re: [PHP] PHP Session Problem!.....urgent!

2003-08-14 Thread CPT John W. Holmes
From: [EMAIL PROTECTED]
 Dear Sir,

You don't have to call me that unless you're in the military, also. :)

 I've been using PHP for business and personal use for a while now, and I
 have to admit, I'm not just a user anymore and I am a fan. but it's been a
 while I came across a problem : I use session variables a lot for security
 purposes but I notice that PHP doesn't hold the session variables when I
 go from one URL to another URL.These are 2 different domains but located
 on the same server and in my php.ini I set a separate temp folder outside
 of both of those domains' folders,
 do you have any idea how I can solve this problem ?...so far the only
 solution I've found is that I pass the session ID to that page that's on
 the other server and then I can get access to session variables. It's just

That's how you HAVE to do it. If I understand you correctly, you've already
got both sites storing their session files in the same directory. Passing
the SID between sites is the only way to maintain that same session.
Sessions normally use cookies, which are tied to a domain and will not be
sent when you switch domains, that's why you pass the SID.

 that if the person who is already logged in my system and they type in a
 different URL which is part my system also it's just a different URL , I
 lose them.

Nothing you can do about that. Get them to use links.

---John Holmes...


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



Re: [PHP] Sum a column of values from a MySQL query

2003-08-14 Thread CPT John W. Holmes
Sorry, Jay, but that's a horrible method. You could just run one query with
a GROUP BY clause to get the sum for each invoiceID, instead of running
multiple queries like you've mentioned...

$query = SELECT invoiceid, SUM(partpaidamount) AS partpaid FROM $tb_name
GROUP BY invoiceid;
$rs = mysql_query($query) or die(mysql_error());
while($r = mysql_fetch_assoc($rs))
{ echo Invoice: {$r['invoiceid']}, SUM: {$r['partpaid']}; }

---John Holmes...

PS: Sorry for the top post, but I'm at work and outlook express sucks. :)

- Original Message - 
From: Jay Blanchard [EMAIL PROTECTED]
To: Ben C. [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Tuesday, August 05, 2003 8:29 AM
Subject: RE: [PHP] Sum a column of values from a MySQL query


[snip]
1) The code returns the sum of a partially paid invoice.  The individual
invoice is 'partpaid'. WORKS...NO PROBLEM
2) The while() then return a list of partially paid invoices which is
$invoicepartpaid.  WORKS..NO PROBLEM
3) I then want to add the list of partially paid invoices
($invoicepartpaid)
together.  I AM STUCK HERE ADDING THE INVOICES AMOUNTS TOGETHER.
[/snip]

Ben...do you want to add together invoices where each ID is different?
Is that right? If so I have the answer! You need to loop through the
ID's which you are not doingI have taken your code and added to
it(and made changes for clarity in the e-amil)

//get invoice id's
$sql_1 = SELECT DISTINCT(invoiceid) as inid FROM $tb_name ;
$result_1 = mysql_query($sql_1, $connection) or die(mysql_error());

while($idinvoice = mysql_fetch_array($result_1)){
 // get partial paid for THIS invoice
 $sql_2 = SELECT SUM(partpaidamount) as partpaid ;
 $sql_2 .= FROM $tb_name ;
 $sql_2 .= WHERE invoiceid = ' . $idinvoice['inid'] . ' ;
 $result_2 = @mysql_query($sql_2,$connection) or die(mysql_error());
 //you will only be returning ONE row, so no need for while loop
 $row = mysql_fetch_array($result_2);
 $invoicepartpaid = $row['partpaid'];
 $total = $total + $invoicepartpaid;
} // loop to NEXT invoice

print(number_format($total, 2, '', ','). \n);

Does this make sense? You must loop through each ID and query for that
ID's partial amount.

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


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



Re: [PHP] greedy preg

2003-08-14 Thread CPT John W. Holmes
From: skate [EMAIL PROTECTED]
 $contents = preg_replace( |item.*?.$file..*?/item|si, ,
 $contents );

 okay, so i figured out that it's matching the first occurence of item
 which will always be the first record and then going on to match the $file
 and deleting everything between. obviously not what i want.

 without giving item a unique attribute and without preg_match_all and
 looping through them all, is there any other way to do this? make it find
 the first occurence of item previous to $file, rather than from the
start?

 i hope this makes sense, and is a little clearer than i've been so far...

This example works... adapt to your needs. (Sorry for the delay)

?php

$xml = 
item
  nameJohn/name
  filefile1.xml/file
  xFoobar/x
/item
item
  nameBob/name
  filefile2.xml/file
  xSomething/x
/item
item
  nameGeorge/name
  filefile3.xml/file
  xGotcha/x
/item
;

$file = 'file2.xml';

function callback($matches)
{
global $file;
if(strpos($matches[1],$file) === FALSE)
{ return $matches[0]; }
else
{ return ''; }
}

$new_xml = preg_replace_callback('|item(.*)/item|Usi','callback',$xml);

echo nl2br(htmlentities($xml));
echo hr;
echo nl2br(htmlentities($new_xml));

?

---John Holmes...


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



Re: [PHP] image button problem

2003-08-14 Thread CPT John W. Holmes
From: Abdul-wahid Paterson [EMAIL PROTECTED]
 I am trying to create an HTML form that has several image buttons on it
 and the resulting action depends on which button is pressed.

 I first tried using input type=image name=test src= but from
 IE on the PHP side I only get $_POST['test_x'] and $_POST['test_y']
 defined. I therefore don't know which of the buttons on the form was
 actually pressed.

What do you mean you don't know what button was pressed? You have 'test_x'
and 'test_y' so you know the test button was pressed. If you give the
other buttons a different name, you'll have different _x and _y variable
names, so you can still tell which one was pressed.

---John Holmes...


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



Re: [PHP] what is %s %d

2003-08-14 Thread CPT John W. Holmes
From: Jackson Miller [EMAIL PROTECTED]


 They are codes for date formatting.

 Specifically:
 %s represents seconds with leading zeros.
 %d represents day of the month with leading zeros

 so
 date(%s %d,mktime());
 would equal something like
 59 08

Actually you'd get:

%59 %08

because date() does not use percent signs in the formatting. However, and I
think this is what you're thinking about, DATE_FORMAT() in MySQL does use
the percent signs like you've demonstrated.

---John Holmes...


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



Re: [PHP] Stop neurotic posting

2003-08-14 Thread CPT John W. Holmes
From: Gabriel Guzman [EMAIL PROTECTED]
 On Wed, 2003-08-06 at 11:44, Chris W. Parker wrote:

  A bad answer would be:
 
  RTFM http://php.net/preg_match;
 
  A good answer would be:
 
  That can be done with a regular expression. The function you're looking
  for is called preg_match. http://php.net/preg_match;

 I fail to see the difference.

Me too. Besides, both answers are wrong. You should use strpos().

---John Holmes...


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



Re: [PHP] mysql_error() problem?

2003-08-14 Thread CPT John W. Holmes
From: Tyler Longren [EMAIL PROTECTED]
 I'm running an UPDATE query on my table.  After executing the query, I
check
 mysql_error() to see if there's any errors:
 if (mysql_error() == ) {
 // success
 }
 else {
 // failure
 }

 mysql_error() is always empty even if the query didn't succeed.  So it
 always thinks it succeeds.  I remember having this problem once quite a
 while ago.  I remember somebody telling me that it had something to do
with
 UPDATE.  Is there a better way to check for errors?

Please define didn't succeed... There is a difference between the query
generated an error which is caught with mysql_error() and the query did
not affect any rows which is caught by mysql_affected_rows().

---John Holmes...


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



Re: [PHP] Array to List

2003-08-14 Thread CPT John W. Holmes
From: James Johnson [EMAIL PROTECTED]

 Actually, I'm using $campusList for a SQL statement:

 SELECT name FROM campuses WHERE inst_id IN ('$campusList');

 It wasn't working until I found out that $campusList needs to look like
 '1','2','3'.

 $campusList = implode( ', ', $_POST['campus'] );

 Returns 4,2,3 (whatever was selected)

 I've looked in the manual on implode, but don't see how to surround each
 value with single quotes. Is there another function that will do this?

You don't need the quotes if the values are integers, but if you insist...

$campusList = ' . implode(',',$_POST['campus']) . ';

The implode pattern is a single quote, comma, single quote, then surround
the whole implode result by single quotes to complete it.

---John Holmes...


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



Re: [PHP] dev style guide

2003-08-14 Thread CPT John W. Holmes
From: [EMAIL PROTECTED]
 Just a remark but isn't it pointless to use Hungariannotation in a
 language that is by default typeless???

I would think that it would be the reason why you WOULD want to use
Hungarian notation (not that I do, though).

Even though you can take nVar and concatinate it into a string, should you?
Maybe you should first cast it to a string, then concatinate... right?

Using the notation would mean that'd you'd know what the varaible was
intended to hold when it was created, even though it can be juggled into
another type by PHP rather easily.

---John Holmes...


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



Re: [PHP] Quick question - Warnings

2003-08-14 Thread CPT John W. Holmes
From: Ryan A [EMAIL PROTECTED]
 I know how to suppress warnings in my file locally but i want to suppress
 warnings and notices in one whole directory using a .htaccess, i cant seem
 to find my old file that does that, can someone refresh my memory please?

 This is how i do it in my local file when i want all ON:
 error_reporting (E_ALL);

 I need to do the opposite by  shuting off all warnings  notices in the
 directory?

php_value error_reporting 0

---John Holmes...


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



Re: [PHP] string concatenation from array

2003-08-14 Thread CPT John W. Holmes
From: Jonathan Pitcher [EMAIL PROTECTED]
 The  sign in PHP (to the best of my knowledge) does not concatenate.

Correct, it's a bitwise AND operator. 

http://us2.php.net/manual/en/language.operators.bitwise.php

---John Holmes...

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



Re: [PHP] Parsing problem with character ''

2003-08-14 Thread CPT John W. Holmes
From: FMM Schillemans [EMAIL PROTECTED]
 I've installed a Win32 package with in it Apache, PHP en MySQL version.

 the problem is that the moment the '' character is placed within the PHP
 code (lets say withing a print-command), then the PHP mode is immideatly
 ends. Making it impossible to create HTML code run-time

 Do you know what a need to change in the configuration files?

Your server is not parsing PHP files correctly or you are not loading them
into your browser correctly. For example:

?php

echo This has a  character in it;

?

If your server does not process PHP correctly, or you load that file into
your browser using File-Open, you'll see:

 character in it;

?

because HTML will see the ?php as the beginning of a tag (unknown tag,
though) and will end the tag with the  character in your string. If you
view the source of the page, though, you'll see all of your PHP code.

---John Holmes...


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



Re: [PHP] trying to match the front and end...

2003-08-14 Thread CPT John W. Holmes
From: Dan Joseph [EMAIL PROTECTED]
 I've searched the high heavens for a method of doing this...  Here's what
 I'm doing... First, the code..

 $middlenum = preg_replace(/^.$this-start_num./, ,
 $this-ach_acct_num);
 $middlenum = preg_replace(/.$this-end_num.$/, , $middlenum);

 In a nutshell, what I want to do is chop off the front and the back.
 Example:

 I have: 1234567890
 I want: 456

 I have a start num and an end num.  start = 123, end = 7890.

 This is working fine as I have it above, however I'd like to combine it
into
 one regular express, instead of two.  Can someone give me an example of
 matching the beginning and end at the same time?

$new_number =
preg_replace('/^'.$this-start_num.'([0-9]+)'.$this-end_num.'$/','\\1',$old
_number);

---John Holmes...


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



Re: [PHP] image button problem

2003-08-14 Thread CPT John W. Holmes
From: Abdul-wahid Paterson [EMAIL PROTECTED]

 What do you mean you don't know what button was pressed? You have
'test_x'
 and 'test_y' so you know the test button was pressed. If you give the
 other buttons a different name, you'll have different _x and _y variable
 names, so you can still tell which one was pressed.

 Yes, I should have specified more accurately. I have quite a few of
 these buttons on one page (approx 30) and really wanted to have the same
 name= for each one and only the value change. The reasoning for that
 is most parts of the page are generated from cached content due to heavy
 processing requirements on making the whole page.

 It is therefore quite difficult for me to change it to something like a
 series of name=test1 and name=test2 for all the buttons as the form
 being POST'd to would have a hard job trying to work out which names
 were valid for the POSTing form.

Diffucult? bah...

form method=GET action=page.php
input type=image name=image[button1] src=pic.gif
input type=image name=image[button2] src=pic.gif
input type=image name=image[button3] src=pic.gif
/form

Then, on page.php, to figure out what button was chosen, you simply use:

$button = each($_GET['image']);

Now, $button[0] or $button['key'] (whichever you want to use) will have one
of the values of button1, button2, or button3 from your form.

Adapt to your needs.

---John Holmes...


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



Re: [PHP] Adding days to a date

2003-08-14 Thread CPT John W. Holmes
From: Donpro [EMAIL PROTECTED]
 I have a piece of code like so:

 $today =- getdate();

 I am looking for a function that will add a variable number of days and
 return a valid date, i.e., the array elements for mday, mon and year
 are reset as needed.  Is this possible?

$tomorrow = getdate(strtotime('+1 day'));

$num_days = 5;
$any_day = getdate(strtotime(+$num_days day));

---John Holmes...


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



Re: [PHP] Session does not end when browser is closed.

2003-08-14 Thread CPT John W. Holmes
From: Lee Hanxue [EMAIL PROTECTED]

 I am using $_SESSION and each php page has session_start() Session
 Handling is working fine, except for one problem: when I close my
 browser and re-open it again, I am still logged in.

 I tested the log in and log out functions and they work fine.

 How can I terminate a session when the user closes the browser?

 All the while I thought a new session will be initiated when a new
 instance of the browser is used to access a page.

check that the session.cookie_lifetime hasn't been extended in php.ini,
.htaccess, or your scripts.

---John Holmes...


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



Re: [PHP] Newbie Session Question

2003-08-14 Thread CPT John W. Holmes
From: Tim Winters [EMAIL PROTECTED]

 Normally to start a session one would use session_start();
  
 Is there a different command to do this if you're instead using the
 $http_session_vars type coding?

No, and it's $HTTP_SESSION_VARS. PHP is case sensitive, remember?

---John Holmes...

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



Re: [PHP] Question on class syntax

2003-08-14 Thread CPT John W. Holmes
From: Luis Lebron [EMAIL PROTECTED]
 I am currently using a php class that uses the following syntax:

 $value= htmlcleaner::cleanup($value);


 What exactly is the :: used for? Is there a different syntax for :: ?

You're calling the cleanup() method of the htmlcleaner class.

You could also have:

$ob = new htmlcleaner;
$value = $ob-cleanup($value);

You can use the first method without having to actually make a new object.
Whether that's better or not depends upon your application. It basically
turns your object into a function repository.

---John Holmes...


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



Re: [PHP] POST/GET - if there is a dot in the name it's changes to _

2003-08-14 Thread CPT John W. Holmes
From: Arnau Rebassa [EMAIL PROTECTED]
   I'm having the same problem as the bug report
 http://bugs.php.net/bug.php?id=7987. They say that's not a bug it's a
 feature... Anybody knows where I can find which characters are changed and
 by which character?

Spaces are also converted to underscore characters. Leading spaces are
trimmed.

name= foobar  = $_GET['foobar_']
name=foo bar = $_GET['foo_bar']

---John Holmes...


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



Re: [PHP] setting function variables

2003-08-14 Thread CPT John W. Holmes
From: Mark [EMAIL PROTECTED]
 --- Micah Montoy [EMAIL PROTECTED] wrote:
  I am trying to specify a single php file to contain all the
  variables and I
  just call this file where necessary.  What I am running into is
  that I want
  to do this for all the built in functions (i.e. mssql_query) as
  well.  I've
  tried numerous attempts but can't get it to operate without wanting
  to run
  the functions or return an error.  Something like this:
  
  $runQuery = @mssql_query;
  $qryResults = @mssql_result;
  $getRow = @mssql_fetch_row;
  $getRowNums = @mssql_num_rows;
 
 Use a database abstraction class (ADODB, Pear, or something from
 phpclasses.org). You're trying to assign a variable to a function's
 actions, when you can only assign the variable to teh ooutput of the
 function.

A good suggestion, since this is what your creating, basically.

Anyhow, if you really want to do it your way, it'd be like this:

$runQuery = 'mssql_query';
$getRow = 'mssql_fetch_row';

Then you'd use them like this:

$result = $runQuery(select ... );
while($row = $getRow($result))
{
  ...
}

---John Holmes...


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



Re: [PHP] Re: why doesn't default values for this function work

2003-08-14 Thread CPT John W. Holmes
From: anders thoresson [EMAIL PROTECTED]
  I want the $max_length to be optional. With your solution it isn't? I
 thought I could make it optional by assigning a default value of -1, which
 would tell the function not to bother with max_length and continue the
 execution.

  All in all my function looks like this (crossing my fingers and hopes
that
 linewrap works this time):

 function secure_string($unsafe_string, $max_length = -1, $errormessage =
 Du har skrivit för många tecken.)
 {
  // verify that string isn't longer then $max_length, if $max_length is
set
  if ($max_length  -1)

Change your logic here...

if($max_length == -1)

then you did not send a value for $max_length and act accordingly.

or

if(!($max_length == -1))

you did send a $max_length value and act accordingly.

---John Holmes...


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



Re: [PHP] Category and sub-category logic

2003-08-15 Thread CPT John W. Holmes
From: Mark [EMAIL PROTECTED]


 I'm trying to get a handle on this algorithm as well. If you add
 additional children to a parent record, doesn't that require
 renumbering all the rgt and lft values in the lineage? For example
 (table shamelessly stolen from a website):

 Personnel
  emp lft  rgt
  ==
  'Albert'  1   12
  'Bert'23
  'Chuck'   4   11
  'Donna'   56
  'Eddie'   78
  'Fred'9   10

 If I want to add 'Joe' as a subordinate to 'Fred', doesn't that mean
 I have to change the lft values for Fred, Chuck, and Albert? Yes,
 deleting definitely seems easier. I'm curious about adding...

Yes, you will have to update all of the right and left numbers to the right
(or higher) than the node where you are inserting. Deleting is basically the
same method done in reverse, but can get complicated when you delete a node
and have to determine what to do with the children.

I'd recommend, if you're really interested in this, to do some searching on
nested set tutorials. You could specifically search for Joe Celko who has
written a lot of information on the topic.

While it seems like a big deal to have to update all of the numbers, it's
really not. It can be done with a single query (with subselects). Yes, it's
more costly than inserting a name into an adjacentcy list model, but it's
worth it for all that you gain from the nested set model.

---John Holmes...


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



Re: [PHP] PCRE regexp bug ?

2003-08-15 Thread CPT John W. Holmes
From: [EMAIL PROTECTED]

 I use preg_match to validate the Middle Initial field of a form and so far
 it works, except yesterday a user submitted a 0 (zero) as a middle
 initial!  My regexp is:

 if (!empty($_POST[MI])  (preg_match('/^[[:alpha:]]{1,1}$/', $_POST[MI])
== 0))

 I tested it with 0-9 and my regexp catches every digit except 0.
Curious...

empty(0) is going to be true. So, !empty(0) is going to be false, so you
won't catch the zero.

---John Holmes...


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



Re: [PHP] Acessing session vars

2003-08-15 Thread CPT John W. Holmes
From: Ed Curtis [EMAIL PROTECTED]
  I just started using sessions and am having some trouble understanding
how
 to pull values out of sessions to use in another page.

 I set the values as:

 session_start();
 session_register{'magazine');
 session_register('company');

 The data is saved as a session because I can read the file located in my
 /tmp directory.

 Now I click on a link and go to a different page and I do:

 session_start()

 Magazine: ? echo $magazine; ?

 Company: ? echo $company; ?

 Should I be able to retrieve the values in this fashion? I'm using php
 4.1.2.

As you sit there and wait for us to answer, you could have taken the 5
second to run this yourself and test it.

If register_globals is ON, then yes, that's how you do it. You may want to
actually assign a value to $magazine and $company in the first script,
though, if you want to see any results.

If register_globals is OFF, then you should do it this way:

Page 1:
session_start();
$_SESSION['magazine'] = 'some value';
$_SESSION['company'] = 'some other value';

Page 2:
?php session_start(); ?
Magazine: ?php echo $_SESSION['magazine']; ?
Company: ?php echo $_SESSION['company']; ?

---John Holmes...


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



Re: [PHP] Category and sub-category logic

2003-08-15 Thread CPT John W. Holmes
From: Richard Baskett [EMAIL PROTECTED]


 Wouldn¹t it just be easier to do a relationship table as in

 Personnel
 emp  ID   parent
 
 'Albert'  1 0
 'Bert'2 1
 'Chuck'   3 1
 'Donna'   4 0
 'Eddie'   5 4
 'Fred'6 0
 'Joe' 7 6

 This way you know the ID of the person and the parentID if they have one,
 otherwise they are a 0 which means they are the parent..  Seems like this
 would be a much easier way of doing it doesn¹t it?  And only one SQL
 query...

Possibly. It depends on what you're trying to model. We're getting way off
topic for PHP, though.

What you gave above is called an adjacency list model and the other example
given was a nested set (or tree) model. Each has it's advantages and
disadvantages. I recommend counsulting your good friend Google if you're
interested in the details. :)

---John Holmes...


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



Re: [PHP] Checkboxes

2003-08-15 Thread CPT John W. Holmes
You could name them as:

input type=checkbox name=choice[] value=1
input type=checkbox name=choice[] value=2
etc...

Then $_POST['choice'] will be an array of the boxes chosen.

$list = implode(',',$_POST['choice']);

will give you a comma separated list of all items chosen.

---John Holmes...

- Original Message - 
From: Cesar Aracena [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, August 15, 2003 2:25 PM
Subject: [PHP] Checkboxes


Hi all,
 
I am wondering what would be the best way to handle checkboxes. I am
making a site that will display several items in a 20-items-per-page
format and each item will have a checkbox next to it for the user to
select them. Now, what I need to do is to record the items selected by
the user when clicking the Next button into a MySQL table. Should I
name all the checkboxes the same, using the item IDs as values and then
use an array to see which ones where selected or maybe another thing?
 
Thanks in advanced,
 
Cesar Aracena
 http://www.icaam.com.ar www.icaam.com.ar
Note: The information inside this message and also in the attached files
might be confidential. If you are not the desired receptor or the person
responsible of delivering the message, we notify you that it's copy,
distribution, keep or illegal use of the information it has it's
prohibited. Therefore we ask you to notify the sender by replying this
message immediately and then delete it from your computer.
 


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



Re: [PHP] getting value of item in list box.

2003-08-18 Thread CPT John W. Holmes
From: Tim Winters [EMAIL PROTECTED]

 I have a PHP page which pulls a bunch of data from a mySQL DB.  I have 2
 list boxes in a form.  One is populated automatically by my PHP code.
 But the second will be populated based on what is selected in the first.

 I don't know how to get out the value of the first listbox using JS.

This is a PHP list. If you have a JavaScript question, please find a
JavaScript list or forum. Thanks.

---John Holmes...


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



Re: [PHP] Problem with the post variables.

2003-08-18 Thread CPT John W. Holmes
Wow... don't do either of those. First of all, you can't use ini_set to
affect the register global settings and you're using the $_POST/$_GET
superglobals, which work regardless of your setting. So that's not the
issue.

Does the phpinfo() function product any output? What if you view the source
of the php file, do you see your PHP code?

---John Holmes...

- Original Message - 
From: Hidayet Dogan [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, August 18, 2003 10:47 AM
Subject: Re: [PHP] Problem with the post variables.


Check your register_globals directive in php.ini file.

If its value is Off, change your register_globals directive to On, and
restart your web server.

Or add ini_set(register_globals, 1); line top of your php file.

 Hidayet Dogan
  [EMAIL PROTECTED]

Pleksus Bilisim Teknolojileri D.T.O. A.S.
--
caldiran sok. 14/6 06420 kolej ankara * www.pleksus.com.tr
tel : +90 312 4355343 * faks: +90 312 4354006

On Mon, 18 Aug 2003, [iso-8859-1] Klaus Kaiser Apolinário wrote:

 Guys I have a problem here.
 I'm using PHP 4.3.2 and httpd 1.3.28.
 Look my exemple.
 I have a page whith a Form method post, and I submit this page to
teste2.php, but I dont can request de data from the text box...


 ###
 This is the test page

 html
 body
 form action=teste2.php method=post enctype=multipart/form-data
 input type=text name=texto
 input type=submit value=ok
 /form
 /body
 /html

 #
 Teste2.php

 ?php
 $string = $_POST['texto'];
 echo Var em post: .$string.br;
 echo Var em get: .$_GET['texto'].br;


 //phpinfo();
 ?
 

 Some one can help me...???

 Klaus Kaiser Apolinário
 Curitiba online


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


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



Re: [PHP] Q: How to get the value of a checkbox of which name without '[]'?

2003-08-18 Thread CPT John W. Holmes
 Consider the following form in a HTML file:



 ...

 input type=checkbox name=box value=1

 input type=checkbox name=box value=2

 input type=checkbox name=box value=3

 input type=checkbox name=box value=4

 ...



 Now I'm posting this form into a PHP script.  The problem is I can't
change

 that HTML file.  Which means I can't modify the code above into PHP
prefered

 style:



 input type=checkbox name=box[] value=1

 input type=checkbox name=box[] value=2

 ...



 So, how can I get the correct values of the checkbox?  $_REQUEST['box'] is

 not an array and only contains the last value.  Thanks!



Parse the value of $_SERVER['QUERY_STRING'] yourself and make the array.



---John Holmes...


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



Re: [PHP] Q: How to get the value of a checkbox of which name without '[]'?

2003-08-18 Thread CPT John W. Holmes
- Original Message - 
From: Frode [EMAIL PROTECTED]
[...snip...]
Which means I can't modify the code above into PHP prefered
style:

input type=checkbox name=box[] value=1
input type=checkbox name=box[] value=2


[...snip...]

 Why is this the preferred style, and where can I read more about it?

I don't know about preferred style or not, but if you want PHP to recognize
multiple values from a form or URL, then you must add the [] onto the name
so PHP will put it into an array. Otherwise you end up with
box=1box=2box=3 and when PHP parses that, each overwrites the other, so
you end up with $box == 3 at the end and the other values are lost. I'm sure
it's discussed in the Form Handling section of the manual.

---John Holmes...


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



Re: [PHP] Stripping out and URL hacking characters from a URL

2003-08-19 Thread CPT John W. Holmes
From: Matt Babineau [EMAIL PROTECTED]

 Does anyone have a function or something they have already written to
 remove any URL hacking characters, mainly the single quote, but I'm
 looking for a nice function to filter my _GET variables against. Gotta
 protect the database...ya know :)

Just escape your single quotes. That's all you need to do. Either use
addslashes() if your database requires quotes to be escaped with a
backslash, or use a str_replace() function if your database requires single
quotes to be escaped with a single quote.

---John Holmes...


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



Re: [PHP] Iterative regular expression replacement

2003-08-19 Thread CPT John W. Holmes
From: Thaddeus J. Quintin [EMAIL PROTECTED]


 I'm looking to replace the 'nth' instance of an expression within a
string.

 Example (very simple)-

 $string=My mom can beat up your mom and your mom's dog;
 $pattern=mom;
 $replacement=dad;

 I want to be able to replace any particular instance of the pattern
 within that string.  I was getting ready to do it in a very complex
 manner by finding all the matches, splitting on the pattern, and then
 breaking the string down and reassembling it in the proper order.  It
 seems like there might be an easier way to perform this though.

 Anyone have any suggestions?

Probably lots of way to do this... here's my suggestion:

?php

//Original String
$str = 'a b c d a b c d a b c d a b c d a b c d';
//Replacement String
$replacement_string = ff;

//Instances of search string you want replaced
//i.e. 2nd and 4th instance is array(2,4)
$instance = array(2,4);

//Callback function that manages replacements
function callback($matches)
{
//Global and static variables. $match_count is
//static to keep track of what match were currently
//operating on
global $replacement_string;
global $instance;
static $match_count = 1;

//determine if current count is in $instance array.
//if it is, set return value to replacement string,
//otherwise return matched value unchanged
if(in_array($match_count,$instance))
{ $retval = $replacement_string; }
else
{ $retval = $matches[0]; }

//increment match count
$match_count++;

//return replacement string
return $retval;
}

//replace all 'a' characters with $replacement_str (simple example)
$new_str = preg_replace_callback('/a/','callback',$str);

echo $str . 'hr' . $new_str;

?

---John Holmes...


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



Re: [PHP] Iterative regular expression replacement

2003-08-19 Thread CPT John W. Holmes
From: Thaddeus J. Quintin [EMAIL PROTECTED]
 I'm looking to replace the 'nth' instance of an expression within a
string.

 Example (very simple)-

 $string=My mom can beat up your mom and your mom's dog;
 $pattern=mom;
 $replacement=dad;

 I want to be able to replace any particular instance of the pattern
 within that string.  I was getting ready to do it in a very complex
 manner by finding all the matches, splitting on the pattern, and then
 breaking the string down and reassembling it in the proper order.  It
 seems like there might be an easier way to perform this though.

 Anyone have any suggestions?

Along with my other suggestion, if you're really looking to replace one
string with another, instead of a regular expression pattern, then you could
use this code, also:

?php

//Original String
$str = 'bb a a a a a a a a a a bb';
//Search String
$search_string = 'a';
//Replacement String
$replacement_string = 'ff';

//Instances of search string you want replaced
//i.e. 2nd and 4th instance is array(2,4)
$instance = array(2,4,6);

//Explode original string by search string
$ar = explode($search_string,$str);

//Get count of elements. Subtract one since you
//do not to loop through last element
$c = count($ar) - 1;

//Holder for new string
$new_str = '';

//Loop from zero to number of matches minus one ($c).
for($x=0;$x$c;$x++)
{
//Add current element to new string
$new_str .= $ar[$x];

//if current count is in $instance array, add replacement string
//otherwise add back original search string
if(in_array($x+1,$instance))
{ $new_str .= $replacement_string; }
else
{ $new_str .= $search_string; }
}
//add on final element of array
$new_str .= $ar[$x];

//Display results
echo $str . 'hr' . $new_str;

?

---John Holmes...


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



Re: [PHP] deleting session variables

2003-08-19 Thread CPT John W. Holmes
From: Tim Winters [EMAIL PROTECTED]
 Is there a way to wipe out all previous session variables with one
 command?

With register_globals OFF:

$_SESSION = array();

If register_globals is ON and you want to get rid of $val1, $val2, $val3,
etc... then:

foreach($_SESSION as $key = $value)
{ unset($$key); }

---John Holmes...


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



Re: [PHP] one out of four session variables lost

2003-08-19 Thread CPT John W. Holmes
From: anders thoresson [EMAIL PROTECTED]


  $_SESSION['uname'] = $_POST['uname'];
  $_SESSION['pwd'] = $_POST['pwd'];

  When the user first logs in I also adds two more session variables within
 accesscontrol():

  $_SESSION['editor'] = mysql_result($result,0,u_editor);
  $_SESSION['admin'] = mysql_result($result,0,u_admin);

  Both is either an Y or a N. When showing menus, I use these two session
 variables to decide wether editor and admin menus should be shown to the
 present user. Like this:

  include (schedule.php);
  if ($_SESSION['editor'] == Y)
   include (editor.php);
  if ($_SESSION['admin'] == Y)
   include (admin.php);

  But something strange happens. Sometime, while an user who is both admin
 and editor is logged in, the $_SESSION['editor'] variable is dropped,
 causing the editor menu not being shown.
  A check through all my source code shows that the only instance where I
 assign is in accesscontrol() shown above.

  Are there any known circumstances where session variables are lost?

  (I guess that the answer is no, and this is an error caused by myself,
but
 since I can't find it, I have to ask ;)

I'll say that the answer is no, also. If it's a case of one session variable
being lost while the others remain, then it's a problem with your code.
somewhere, somehow, you're assigning a value to that session variable and
not realizing it.

If all of the session variables are lost, then it's still a problem with
your code and there are more possibilities. Perhaps the session ID isn't
being transmitted or the domain is changing?

---John Holmes...


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



Re: [PHP] Not fair: REMOTE_HOST

2003-08-19 Thread CPT John W. Holmes
From: John Taylor-Johnston [EMAIL PROTECTED]


 Aw gee, $_SERVER['REMOTE_HOST'] (only REMOTE_ADDR) does not exist in PHP?
 Bummer.
 Why is that?

Probably to expensive to look up with every request. Look it up yourself.

http://us2.php.net/manual/en/function.gethostbyaddr.php

---John Holmes...

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



Re: [PHP] deleting session variables

2003-08-19 Thread CPT John W. Holmes
From: Tim Winters [EMAIL PROTECTED]

 So what does session_unset() do then?

Ah, good catch. Use that instead of my second example. If register_globals
is ON, it appears that session_unset() will take care of getting rid of the
global variables made.

---John Holmes...

 From: CPT John W. Holmes [mailto:[EMAIL PROTECTED]
 Sent: August 19, 2003 5:11 PM
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Subject: Re: [PHP] deleting session variables

 From: Tim Winters [EMAIL PROTECTED]
  Is there a way to wipe out all previous session variables with one
  command?

 With register_globals OFF:

 $_SESSION = array();

 If register_globals is ON and you want to get rid of $val1, $val2,
 $val3,
 etc... then:

 foreach($_SESSION as $key = $value)
 { unset($$key); }

 ---John Holmes...


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



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



Re: [PHP] mysql output

2003-08-19 Thread CPT John W. Holmes
From: Curt Zirzow [EMAIL PROTECTED]


 * Thus wrote Anthony Ritter ([EMAIL PROTECTED]):
  The following code snippet outputs a table from a mySQL database.
 
  [snipped 255+ lines of code]

 That is way to much information, please be a brief in your code
 that you post.  You'll find you'll get more people to analyze your
 code.

You also asked a very, very common question, i.e. how to alternate colors in
table rows... there are a ton of websites/tutorials out there that explain
ways to do this.

---John Holmes...


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



Re: [PHP] String parsing help

2003-08-20 Thread CPT John W. Holmes
From: Jonatan Pugliese. [EMAIL PROTECTED]
 From: Matt Matijevich [EMAIL PROTECTED]
  I have have a string that I need to split into 3 different variables:
  City,State, and Zip.  Here is a couple examples of the strings I need to
  parse:
 
  ANCHORAGE  AK  99507-6420
  JUNEAU  AK  99801
  NORTH LITTLE ROCK  AR  72118-5227
 
  Does anyone have an idea how I could slit this into the appropriate
  variables, maybe some kind of regular expression?  I cant use the space
  character to split the data because some of the city names have spaces
  in them.

 $vector=split(  , $string, );


 $City=$vector[0];
 $State=$vector[1];
 $Zip=$vector[2]:

Umm, no. then you'll have $City = North, $State = Little and $Zip =
Rock with the last example.

The following works:

?php

$str = NORTH LITTLE ROCK  AR  72118-5227
JUNEAU  AK  99801
ANCHORAGE  AK  99507-6420
NORTH CARO  MI  48732
;

preg_match_all('/^(.*)([a-z]{2})\s+([0-9]{5}(-[0-9]{4})?)/im',$str,$matches)
;

$count = count($matches[1]);

echo $count . ' addresses found:br /';

for($x=0;$x$count;$x++)
{
$city = trim($matches[1][$x]);
$state = trim($matches[2][$x]);
$zip = trim($matches[3][$x]);
echo City: $city, State: $state, ZIP: $zipbr /;
}

?

---John Holmes...


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



Re: [PHP] Question for you guys and gals

2003-08-22 Thread CPT John W. Holmes
From: David Smith [EMAIL PROTECTED]
 I have a problem. I have all my functions (currently) set aside in one
 file, and I just require_once that page for all of the other pages that
 may need any of those functions. In those functions I have it setup to
 echo the link to the CSS page for my site (just a very lazy way of doing
 it). My problem is on the sites that I use cookies or use the header to
 redirect a page. How can I still have my CSS on my functions page and
 not have problems with header errors because of this already being at
 the top...recommendations?

You already know the answer, stop doing it the lazy way. Have a function
that creates your header with the CSS links and call that function only
after you've determined you don't need to set a cookie or another header().

Or cheat and use output buffering.

---John Holmes...


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



Re: [PHP] Question for you guys and gals

2003-08-22 Thread CPT John W. Holmes
From: Curt Zirzow [EMAIL PROTECTED]

  Or cheat and use output buffering.

 IMO, thats an even more lazy way of doing it.

I agree entirely. I hate even giving that option, but it is there. That's
why I said he could cheat :)

---John Holmes...


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



Re: [PHP] '' Sign in _GET Parameter

2003-08-22 Thread CPT John W. Holmes
From: Pushpinder Singh Garcha [EMAIL PROTECTED]

   I am using an application where I retrieve user profile from a MySQL
 DB using the Company Name .  I pass the name of the company to the PHP
 script as a '$_GET' parameter. e.g. when the name of the company is
 'IBM'. , the URL with the query string would look like :
 http://masterstream.com/CRM/full_profile_1.php?name=IBM

 Now one of the records had a name : PSG  Inc. , in this case the URL
 with the query string would look like
 http://masterstream.com/CRM/full_profile_1.php?name=PSG%20%20Inc.

 However in the case of the latter I am not able to pull out any records
 from the MySQL database. It says that no records with the name were
 found.   I went ahead and tweaked the name of the company, to remove
 the  sign in 'PSG  Inc.'   Now the query works fine.  Can some one
 throw some light here. I am sure something minor is to be done when
 passing the name of the company in the parent script.

The  character separates variables in the query string, so it must be
encoded if it appears in the data. Take a look at
http://us2.php.net/urlencode

---John Holmes...


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



Re: [PHP] timestamp

2003-08-22 Thread CPT John W. Holmes
From: John Taylor-Johnston [EMAIL PROTECTED]


 I'm creating a counter.

 I want a timestamp where I can calculate if a time stamp is older than one
hour, if so do X, if not do Y.

SELECT * FROM Table WHERE timestamp_column  NOW() - INTERVAL 60 MINUTE

will give you all rows that have a timestamp column that's over 60 minutes
old. Adapt to your needs.

---John Holmes..


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



Re: [PHP] problem passing variable between forms.

2003-08-26 Thread CPT John W. Holmes

- Original Message - 
From: Angelo Zanetti [EMAIL PROTECTED]
 I have a form in which I have a table with dynamic checkboxes, they are in
a
 checkbox array ( name = chk[]...), I pass this variable to the next page
 using POST I receive the variable and use it, no problem, but then when I
 try to pass it to the next form in the URL (using an A HREF:

 a href='confirmrequest.php?requested= . $chk . '  )

You need to serialize() the array in order to pass all of it's values.

$ser = urlencode(serialize($chk));

$url = confirmrequest.php?requested=$ser;

Then on the receiving side...

$chk = unserialize($_GET['requested']);

You could also just add it to the session and make it easy...

$_SESSION['chk'] = $chk;

and on the receiving page:

$chk = $_SESSION['chk'];

---John Holmes...

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



Re: [PHP] math functions?

2003-08-26 Thread CPT John W. Holmes
From: Amanda McComb [EMAIL PROTECTED]


 I am having trouble finding math functions on php.net.  I am also getting
 page not found errors when trying to search.
 
 Basically, I'm looking for a mod or division function - something I can
 use to tell me when a number is evening divisable by a certain number.

% is mod, / is division...

$a = 10;
$b = 5;

if($a % $b == 0)
{ echo evenly devisable; }

Arithmetic Operators:
http://us2.php.net/manual/en/language.operators.arithmetic.php

Math Functions:
http://us2.php.net/manual/en/ref.math.php

BCMath Functions
http://us2.php.net/manual/en/ref.bc.php

---John Holmes...

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



Re: [PHP] PHP Interview questions

2003-08-26 Thread CPT John W. Holmes
From: Micheal Harris [EMAIL PROTECTED]

 I am in the process of hiring someone that needs to have extensive PHP and
 MySQL experience. Does anyone have any suggestions for interview
questions?
 I have no PHP or MySQL experience, and come from a non-technical
background.
 I want the questions to be technical, but I am unsusre as to how specific
I
 should get with the questionning!

How are you going to grade it, though, if you don't know PHP or MySQL?

I say you should send them to the list and let us grill them!! We'll sort
out the riff-raff.. :)

Seriously, look at their portfolio, call their references, and MAKE them
write code.

TASK: Create a PHP application that will insert names and dates of birth
into a MySQL database.

CONDITIONS: Given the PHP Manual, MySQL Manual, Notepad (or similar text
editor), and database host, user, and password information.

STANDARD: The application will run without errors when complete. The
application will accept a first name, last name, and date of birth (in
DDMMMYY format) through an HTML form and store the information in a MySQL
database. The application will list all current entries in the database in
an HTML table after a new row is inserted.

Things to look for:

1. Do they program for register_globals ON or OFF?
2. Do they check the setting of magic_quote_gpc?
3. Do they include error checking of form data and queries?
4. Is their program open to cross site scripting or SQL injection attacks?
5. Do they use a DATE type column or VARCHAR column for dates?
6. Do they write valid HTML?
7. How many files do they use to accomplish the task?
8. Do they try to add extra fluff instead of just accomplishing the task?

Hopefully others will pipe up with their comments, also. :)

---John Holmes...

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



Re: [PHP] Serve a file using PHP

2003-08-26 Thread CPT John W. Holmes
From: Grant Rutherford [EMAIL PROTECTED]
 Is there a way that PHP can allow a user to browse the files on the
 server's network, and ultimately send the file to the user?

 I'm making a database interface with PHP to be used internally on our
 network.  Through a PHP interface, the user wants to browse their
 network and find a file, and insert the file's path into the database.
 The user then wants the database to display a link, which when clicked
 will open the file.  They want this to work in Mozilla or IE, on both
 windows and linux machines.  I tried making the path a link with
 file://path, but Mozilla wouldn't follow the link (probably a security
 thing; it makes sense that links shouldn't open local files).

 Is there a way that I can give PHP the network path (through $_POST for
 example), and it would return the file instead of an HTML document?

Can't you just link to \\computer_name\path\to\file.doc (or whatever the
filename is) ?

file:/// would try to load it off of their machine, not a network machine.

---John Holmes...

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



Re: [PHP] PHP Interview questions

2003-08-26 Thread CPT John W. Holmes
From: Jay Blanchard [EMAIL PROTECTED]

 Also ask a couple of other questions that require thought, but have
 nothing else to do with code. such as...

 In one room you have 3 light switches, each connected to one light bulb
 in another room. How many trips must you make to determine which switch
 is connected to which light bulb?

PHP is server side, so it obviously cannot control light bulbs. Use
javascript.

---John Holmes...

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



Re: [PHP] verifying sql INSERTs

2003-08-26 Thread CPT John W. Holmes
From: Chris W. Parker [EMAIL PROTECTED]

 I should instead just try to perform the INSERT and then if it fails I
 know I've already got a record. If it doesn't I know everything is cool.

If it is a certain kind of failure, then you have a duplicate, otherwise it
could be another type of failure/error. Use mysql_errno() to make sure you
catch the right error as a duplicate.

---John Holmes...

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



Re: [PHP] Website templating schemes

2003-08-26 Thread CPT John W. Holmes
From: Joel Konkle-Parker [EMAIL PROTECTED]


 I'm trying to make a PHP-backed website, and I'm trying to decide between
two
 templating schemes:

 1. define 2 php template files: header.php, footer.php. in index.php,
require
 header.php, output content, require footer.php

 2. define a php template file and a local page file. index.php defines
body()
 and crequires template.php. template.php prints the header, calls body()
to
 print the content, and and prints the footer.

 I'm currently using the second method, but I've only seen the first used
 elsewhere. Is there a reason that #1 is better than #2 (or is anything
else even
 better than that?)?

With method 2 it seems like your template file would become redundant
because every one of them would have to contain the header and footer code.

I would use 3 template files, header.php, footer.php, and body_index.php

index.php would:

1. PERFORM LOGIC
2. include header
3. include body
4. include footer

Then, all you have to do is make new body_XXX.php files for each page on
your site and the header/footer content is contained in one place.

---John Holmes...

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



Re: [PHP] verifying sql INSERTs

2003-08-27 Thread CPT John W. Holmes
From: Curt Zirzow [EMAIL PROTECTED]

  I should instead just try to perform the INSERT and then if it fails I
  know I've already got a record. If it doesn't I know everything is cool.

 I've debated with myself several times if this is really a good
 method to not have duplicates in the database.

 Like what happens if for some reason the constraint gets dropped?
 having your progam rely on the constraint will cause all data
 integrity to go to hell.

For one little script inserting into it's own little table, yeah, it really
doesn't matter.

Consider, though, a business making use of this database not only through a
PHP script, but through an Access frontend in marketing, some ASP scripts in
HR, etc. Now, if you don't enforce the constraints in the database, each and
every program must enforce the constraits itself. It's easier to do it in
one place. :)

---John Holmes...

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



Re: [PHP] PHP Interview questions

2003-08-27 Thread CPT John W. Holmes
From: Curt Zirzow [EMAIL PROTECTED]

 toggle_light(1);
 sleep(120);
 toggle_light(1);
 
 toggle_light(2);
 move('self', 'room/');
 
 if ($lightbulb['temp']  $room['temp']) {
   echo switch #1;
 } elseif ($lightbulb['ison']) {
   echo switch #2;
 } else {
   echo switch #3;
 }
 
 hm.. i had to keep it OT somehow :)

Aren't you missing a foreach($lightbulb as $bulb) in there somewhere?

---John Holmes...

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



Re: [PHP] Looping through a list - Newbie question

2003-08-27 Thread CPT John W. Holmes
From: James Johnson [EMAIL PROTECTED]
 I have a list contained in a session var. I want to loop through the list,
 getting the value of the current item, then do a query based on that
value.
 Is there an easy way to do this, or do I need to convert the list to an
 array first? In the code below, $id isn't being set.

 Here's my code (this is just testing stuff, sv_CampusList is set somewhere
 else):
 ?php
 session_start();
 $_SESSION['sv_CampusList'] = 1,2,4,5;
 for($i=1; $i=strlen($_SESSION['sv_CampusList']); $i++){
 $id = strpos($_SESSION['sv_CampusList'],$i);
 echo $id;
 }
 ?

What are you actually trying to accomplish here? I could tell you how to
loop through a list in a string and run a query for each number, but I'd
have the horrible feeling that you're using some inefficient method to
accomplish something.

For instance, if you're just trying to select data matching the numbers in
your list, you can do this:

$query = SELECT * FROM Table WHERE campus_list IN
({$_SESSION['sv_CampusList']});

---John Holmes...

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



Re: [PHP] dealing with arrays

2003-08-27 Thread CPT John W. Holmes
You need to name the elements a little differently. You're on the right
track with making them an array, but if I check the third box, that'll make
$check[0] = 1, and if I put in a name in the first box, that'll make
$name[0] = 'John'... so you have no way of relating the name from entry
one to the checkbox in entry one.

So, the easy fix for this is to supply the key yourself.

pEntry One
input type=text name=name[1]
input type=text name=tel[1]
input type=checkbox name=check[1] value=1

pEntry Two
input type=text name=name[1]
input type=text name=tel[1]
input type=checkbox name=check[1] value=1

Now, when that is submitted, only the checked values will be passed in
$check.. so you can do this (assuming POST):

foreach($_POST['check'] as $key = $value)
{
  if(empty($_POST['name'][$key]))
  { echo you didn't supply a name for entry $key; }
  if(empty($_POST['tel'][$key]))
  { echo you didn't supply a telephone number for entry $key; }

  //process $_POST['name'][$key] and $_POST['tel'][$key]
}

Hope that helps. Sorry for the top post, but OE sucks. :)

---John Holmes...

- Original Message - 
From: Aris Santillan [EMAIL PROTECTED]
To: Php (E-mail) [EMAIL PROTECTED]
Sent: Tuesday, August 26, 2003 11:21 PM
Subject: [PHP] dealing with arrays


hi


I Have
pEntry One
input type=text name=name[]
input type=text name=tel[]
input type=checkbox name=check[] value=1

pEntry Two
input type=text name=name[]
input type=text name=tel[]
input type=checkbox name=check[] value=1

pEntry Three
input type=text name=name[]
input type=text name=tel[]
input type=checkbox name=check[] value=1

pEntry Four
input type=text name=name[]
input type=text name=tel[]
input type=checkbox name=check[] value=1

pEntry Five
input type=text name=name[]
input type=text name=tel[]
input type=checkbox name=check[] value=1

.

i want to process entries only with checked checkbox

how can i do this in php?

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



Re: [PHP] Cannot pass values from one page to another

2003-08-27 Thread CPT John W. Holmes
From: [EMAIL PROTECTED]
 Ok this is a major vulnerability that you are coding. Register globals 
 on and password being stored in the session is like having a banner on 
 your home page saying 'come and hack me'.

Please explain how you've come to this conclusion...

---John Holmes...

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



Re: [PHP] Implode slows down file reading? [was: str_replace performance in large mailing script]

2003-08-27 Thread CPT John W. Holmes
From: frederik feys [EMAIL PROTECTED]

 I thought str_replace caused slow down of my mailing script, but it
 seems to be this line of code:

 $fd =
 implode(,file(http://www.domain.org/store/min/Mailing_template.html;)
 );

 I first put the mailing template in $fd (only once) and then replace
 (str_replace) elements of it to individualize HTML emails.
 Btw i'm using php version 4.0.6.

 Are there better(faster) ways to read the contents of a file?

file_get_contents() ?

The slow down is probably because you're going through HTTP to read the
file. Is there a reason for that? Any way you can cache the file locally so
it's not read through HTTP all of the time?

---John Holmes...

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



Re: [PHP] Cannot pass values from one page to another

2003-08-27 Thread CPT John W. Holmes
From: [EMAIL PROTECTED]

 Didn't know this was the army :-)

Yeah, I signed you up last week. You report to basic training in November. I
hope you're ready! :)

 first unless you got your variable ordering (POST, GET, Env, Sesssion
 etc). the values in the session can be easily overridden with a simple
 old query string. Sure would hate to have my username and password
 passed along to each page. remember that when you are using cookies the
 data actually get's transferred between the client and the server.

By default, sessions are made global last, so the session value would
overwrite anything passed. But, yes, you're right that if some idiot changed
the order around (why?) then it could present a security problem. Thanks for
the explanation (just checking!) :)

---John Holmes...

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



Re: [PHP] session.cookie_domain

2003-08-27 Thread CPT John W. Holmes
From: Shu Chow [EMAIL PROTECTED]
 We're having a problem with a site that recently upgraded to php 4.3.3.
   Ever since the upgrade, session variables won't pass between pages.
 Looking at the php.ini file, I see that session.cookie_domain is set to
 server.hostingcompany.com while our site is www.ourdomain.com.  If the
 session.cookie_domain is set to another domain, would this be the cause
 of our problems?

Yeah, that'd cause problems. You can set your own value for the domain using
an .htaccess file or the session_set_cookie_params() function

http://us2.php.net/manual/en/function.session-set-cookie-params.php

---John Holmes...

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



Re: [PHP] Session var read by form C++ CGI prog ?

2003-09-02 Thread CPT John W. Holmes
From: John Bryan [EMAIL PROTECTED]


 If so, the problem is that this file that is being uploaded
 via the form to the program MyCppProg.exe gets sent
 as THE input to the prog, apparently as a cgi-type
 parameter through stdin (i.e. cin), so that when I try to
 pass the value as a cgi parameter, it gets inserted INTO
 the file that is being uploaded.

Does this file already exist or are you looking to create it? It sounds like
you just need to fopen() the file, tack on your variable at the end of the
file (in some format) and then let the C++ program load the file, right?

---John Holmes...

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



Re: [PHP] Session var read by form C++ CGI prog ?

2003-09-02 Thread CPT John W. Holmes
From: John Bryan [EMAIL PROTECTED]

 The file would already exist on the client side.  They are
 uploading the file to be processed by this program
 MyCppProg.exe, which is invoked as a form 'action'.
 This already works, but depends on the Apache variable
 REMOTE_USER being set when user logs in, but we
 moving to implement a different method for authentication
 that involves talking to two different Oracle databases,
 password rules, etc., so this REMOTE_USER variable
 no longer gets set since we are bypassing Apache's
 authentication here.

 So I need to set an 'environment' variable that remains
 visible to scripts and progs within the session space, that
 can then be grabbed by the MyCppProg.exe, for example
 with getenv(MyEnvVar).  It used to use getenv(REMOTE_USER).

 I'm hoping to not have this variable have to be part of the file that gets
uploaded.

Ah, I see now.

If you're using a file upload box and submitting that form directly to your
.exe, then there's probably not much you can do.

In order to do this, I think you'll have to intercept the file.

When the user submits the file, it goes to a PHP script that copies it
somewhere. Then see if you can make an exec() call to the system and set the
REMOTE_USER variable, somehow. I'm not sure on the syntax/possibility of
that, it would depend upon your OS. Then make another exec() call to your
C++ program and send it the path the the file that was already uploaded.
Capture the output and show it to the user or do whatever you normally do.

---John Holmes...

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



  1   2   3   4   5   >