[PHP] Fwd: FACEBOOK MALWARE BOTNET

2010-03-23 Thread Allen McCabe
*Importance:* High



All:



If you are a Facebook user, you may have recently received an email with the
subject:  *Facebook Password Reset Confirmation Customer Support.
**The *address
of the sender is spoofed to display supp...@facebook.com



*THIS IS MALWARE BOTNET – DO NOT OPEN THIS MESSAGE!*



The message reads, “*Dear user of Facebook, Because of the measures taken to
provide safety to our clients, your password has been changed. You can find
your new password in attached document. Thanks, Your Facebook.*”

*According to TrendMicro, “The malware being delivered is a botnet and is
called ‘BredoLab.’ It has been occasionally spread by spam since May of
2009,**” **There have been at least eight versions of the Facebook BredoLab
malware observed since March 16, 2010**.  *

*“**What is troubling is the newer versions of the BredoLab used in this
latest attack campaign are not being detected by the majority of anti-virus
services — and that means the majority of users who unwittingly click on the
bogus attachments linked to fake e-mails are going to have their computers
infected**“.  *To bypass firewalls, it injects its own code into legitimate
processes.**

The malicious executable is linked to the Bredolab botnet, which has been
linked to massive spam runs and identity-theft related attacks.



BREDOLAB is a software that enables cybercriminal organizations to deliver
any kind of software to its victims.  Once a user’s machine is infected by
BREDOLAB, it will receive regular malware updates the same way it receives
software updates from the user’s security vendor.



To clean and protect your home machine, both anti-virus and
anti-malware/anti-spyware software should be run daily (or nightly).


Re: [PHP] Appalling Dreamweaver performance

2010-01-31 Thread Allen McCabe
Notepad++ also has session saving capabilities. This means you can save
which files you're working on, close Notepad++, and reload those files at a
later date. It's cool.

On Sun, Jan 31, 2010 at 4:51 PM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 On Mon, 2010-02-01 at 11:28 +1100, clanc...@cybec.com.au wrote:

  I use Dreamweaver as my editor, mainly because I'm familiar with it,
 although I only use
  about 1% of its capabilities. However it generally handles long files
 well.  The other day
  I downloaded the two shortest of Brian Dunning's sets of test data *.  I
 opened the
  shortest in Dreamweaver, had a quick look at it, and realised I would
 have to replace the
  quote, comma, quote separators with semicolons, as part of converting the
 files to my
  format.
 
  So I thought I would do that while I was working out what else I had to
 do. I entered the
  old separator and the replacement in the 'Find and replace' window, then
 hit 'Replace
  all', expecting the job be done in a few seconds. First I thought nothing
 was happening,
  but then I realised it was trudging through the file, as if it was wading
 through waist
  high molasses.
 
  So I closed the results window, and opened another file, but a few
 seconds later focus
  switched back to the original file. I tried a couple of times more, but
 each time it
  returned to the original window. I watched in morbid fascination for a
 bit, then decided I
  would let it go, just to see how long it took.
 
  The file contained 500 lines, and was about 80 K. It was taking five
 seconds to process
  each line, and eventually finished in about 40 minutes.
 
  The problem appeared to be the results processing. I have only looked at
 the results list
  about twice, out of idle curiosity, but never saw any thing that I
 thought could be
  remotely useful. I would like to be able to turn results logging off
 altogether, as it
  wastes real estate (and time!), but this appears to be impossible.
 
  On this occasion the program was apparently writing a new line every time
 it replaced a
  separator (9 times in each line), and then when it finished processing a
 line it would
  erase all the intermediate result lines, and write a new one for the
 whole line.  At the
  same time it reopened the results window if I had closed it, and return
 focus to the file
  being processed.
 
  I then wrote a PHP program to read the file, split it, clean up and
 re-arrange the various
  elements, enter them into an array in my format, and finally save it as a
 file my program
  could handle.
 
   After I had got this running on the 500 line file I used it to process
 the 5000 line
  file. The whole process was done in the blink of an eye -- literally a
 fraction of a
  second.
 
 
  * http://www.briandunning.com/sample-data/
 
 


 Don't use Dreamweaver then :p

 Joking aside (Dreamweaver is a very capable editor, although it is quite
 large for simple find and replace tasks) how were you performing the
 find and replace? Regular expression replacements will be much slower,
 although it shouldn't account for quite the speed hit you saw. For
 simple tasks like that, I'd recommend Notepad++. It has code
 highlighting and folding, regex find/replace features, and a slew of
 other bits that make it a very good editor, and it's very speedy to
 boot.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk





Re: [PHP] Reports generator

2010-01-28 Thread Allen McCabe
 class, that sits below all the plugins (and the
 top-class).
 And i highly recommend adodb.sf.net as the db-abstraction layer, to be
 used exclusively for all db access by all other classes.

 On Thu, Jan 28, 2010 at 5:20 AM, Allen McCabe allenmcc...@gmail.com
 wrote:
  I actually started on a report class yesterday, and I have a few
 questions,
  but first some details:
 
  - Reports will be on user orders (ticket reservations).
  - Need to be able to build a large variety of reports based on existing
 data
   + Orders by a specific user
   + Orders for a specific product (event)
   + Orders by a user sub-group (organization)
   + Orders by a user super-group (school district)
  - Reports need data from a primary table (orders) and several secondary
  tables (users, order_lineitems, etc.)
 
  Now, I started to approach this with a class that builds an HTML table
 with
  the data as the end product, based upon the parameters I supply.
 
  There shall be a table_header property which will be an array of column
  names, a rows property which will be a bi-dimensional array which will
  contain the data for each row.
 
  I want to have methods like the following:
 
  ?php
 
  $Report-createNew('orders', 35); // STARTS AN ORDER USING `orders` TABLE
 -
  SHOW ID 35
  $Report-addColumn('contact'); // USERNAME - `users` TABLE
  $Report-addColumn('phone'); // USER'S PHONE NUMBER - `users` TABLE
  $Report-addColumn('quantity'); // TICKETS REQUESTED - `order_lineitems`
  TABLE
 
  // SAVE OBJECT TO `reports` TABLE
  $report = serialize($Report);
 
  $success = mysql_query('INSERT INTO `reports` (`data`) VALUES (\'' .
 $report
  . '\') ;');
 
  if ($success) { $Notify-addtoQ('Report succesfully saved.', 'confirm');
 }
  else { $Notify-addtoQ('There was en error saving the report.', 'error');
 }
 
  ?
 
  I was having a tough time wrapping my head around how to make the report
  class less specific and more flexible. For example, I have the user's
  user_id already stored in the `orders` table (of course, foreign key),
 but I
  want to display their username (or firstname, lastname pair), which would
  require another call to the `users` table, so I had a $queries property,
  which would be an array of queries to execute, but then I couldn't figure
  out how to handle each one, because each is handled uniquely.
 
  So, I have to be less general, and more specific. Call what I want by
  nickname, ie. $Report-addColumn('userRealName'), and have a switch
  statement within the addColumn() method to check for nicknames. Whew!
 That
  sounds awful!
 
  And how do I handle each result in the queries array? Should I create an
  associate array (ie. 'username' = 'SELECT `username` FROM `users`',
  'school' = 'SELECT `name` FROM `organization`... ') and again, have a
  switch statement to determine how to handle the database result arrays?
 
  Can anyone point me in the right direction? Should I just get down and
 dirty
  and write a focused class (or even procedural?) for different types of
  reports that I anticipate needing?
 
 
  This is a tough one! Thanks!
 
  On Wed, Jan 27, 2010 at 4:32 AM, Ashley Sheridan
  a...@ashleysheridan.co.ukwrote:
 
  On Tue, 2010-01-26 at 18:54 +0100, PEPITOVADECURT wrote:
 
   Exists any reports generator that exports directly to html/php?
  
  
 
 
  What do you want to generate reports on? I would assume this would be
  some sort of data from a database, and that you're looking for a
  PHP-based reporting tool that can output as HTML for viewing your
  reports in a web browser?
 
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 
 
 
 



Re: [PHP] Reports generator

2010-01-27 Thread Allen McCabe
I actually started on a report class yesterday, and I have a few questions,
but first some details:

- Reports will be on user orders (ticket reservations).
- Need to be able to build a large variety of reports based on existing data
 + Orders by a specific user
 + Orders for a specific product (event)
 + Orders by a user sub-group (organization)
 + Orders by a user super-group (school district)
- Reports need data from a primary table (orders) and several secondary
tables (users, order_lineitems, etc.)

Now, I started to approach this with a class that builds an HTML table with
the data as the end product, based upon the parameters I supply.

There shall be a table_header property which will be an array of column
names, a rows property which will be a bi-dimensional array which will
contain the data for each row.

I want to have methods like the following:

?php

$Report-createNew('orders', 35); // STARTS AN ORDER USING `orders` TABLE -
SHOW ID 35
$Report-addColumn('contact'); // USERNAME - `users` TABLE
$Report-addColumn('phone'); // USER'S PHONE NUMBER - `users` TABLE
$Report-addColumn('quantity'); // TICKETS REQUESTED - `order_lineitems`
TABLE

// SAVE OBJECT TO `reports` TABLE
$report = serialize($Report);

$success = mysql_query('INSERT INTO `reports` (`data`) VALUES (\'' . $report
. '\') ;');

if ($success) { $Notify-addtoQ('Report succesfully saved.', 'confirm'); }
else { $Notify-addtoQ('There was en error saving the report.', 'error'); }

?

I was having a tough time wrapping my head around how to make the report
class less specific and more flexible. For example, I have the user's
user_id already stored in the `orders` table (of course, foreign key), but I
want to display their username (or firstname, lastname pair), which would
require another call to the `users` table, so I had a $queries property,
which would be an array of queries to execute, but then I couldn't figure
out how to handle each one, because each is handled uniquely.

So, I have to be less general, and more specific. Call what I want by
nickname, ie. $Report-addColumn('userRealName'), and have a switch
statement within the addColumn() method to check for nicknames. Whew! That
sounds awful!

And how do I handle each result in the queries array? Should I create an
associate array (ie. 'username' = 'SELECT `username` FROM `users`',
'school' = 'SELECT `name` FROM `organization`... ') and again, have a
switch statement to determine how to handle the database result arrays?

Can anyone point me in the right direction? Should I just get down and dirty
and write a focused class (or even procedural?) for different types of
reports that I anticipate needing?


This is a tough one! Thanks!

On Wed, Jan 27, 2010 at 4:32 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 On Tue, 2010-01-26 at 18:54 +0100, PEPITOVADECURT wrote:

  Exists any reports generator that exports directly to html/php?
 
 


 What do you want to generate reports on? I would assume this would be
 some sort of data from a database, and that you're looking for a
 PHP-based reporting tool that can output as HTML for viewing your
 reports in a web browser?

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk





Re: [PHP] Open Source CMS

2010-01-20 Thread Allen McCabe
I've not had much experience with CMS's, however Drupal seems pretty
featured, with the steep-learning curve; it's not very user friendly.

I'm working on my own CMS which is more generic, so that it can be used with
any kind of website (basically). I suggest you do the same; have a page
class with methods that allow you to create new pages. I have not yet
fleshed out this class, but I eventually plan to get it so that when I
create a new page, my class will generate a PHP file with a unique page ID
number. Then it will log the link to this page into a links table and save
content I enter in different areas, eg. Scripts (here I write any PHP I will
need) and content (the body of the document, which can also make use of
PHP).

The Scripts and Body are saved to include files with the same name as the
ID, and the page loads the items associated with that ID. For example:

html
head
?php
$pageid = unique_id_here;
query database

include ('../includes/script_' . $pageid);
?
/head
body
?php
include ('content/' . $pageid . '.inc.php');
?
/body
/html


Does this make sense?


Anyone else have any questions/comments/critiques?


On Wed, Jan 20, 2010 at 7:29 PM, Hendry hendry@gmail.com wrote:

 Hi,

 Anyone can share your favorite PHP open source CMS to work with and
 what's the reason? I'm looking for something that easily extensible.
 I've googled and found severals but I'm still confused, some from the
 lists:
 - Drupal
 - Tomato CMS
 - modx
 - xoops
 - Symphony

 Thanks

 # Hendry

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




Re: [PHP] Open Source CMS

2010-01-20 Thread Allen McCabe
For a work in progress, view http://www.mwclans.com/new_index.php

The login fields are a 'component' I include in the header.
The links are generated from the 'links' table; the primary_navigation links
are a class by the same name, and the 'footer_navigation' are also a
different category. All links on this page are generated from the Links
table, and each row has 90% of the properties the HTML 'a' tag can have (eg.
fields: id, link_text, href, target, onmouseover, onmouseout, onclick, name,
class, etc.). The class is the same as the category.

The content is pulled from an include file with the same ID number as this
page (home page), which is 1, and the scripts.

There are additional features, like a theme class which pulls a theme ID
from the DB (a `site_settings` table).

Here is an example of the source code for the above link:




?php
$thispage = 1;
// define root directory
if (!defined('ROOT'))
{
// Locate config.inc.php and set the basedir path
$folder_level = ''; $i = 0;
while (!file_exists($folder_level . 'config.inc.php'))
{
$folder_level .= '../';
$i++;
if ($i == 5){ die('Config file not found.'); }
}

// ROOT = base_directory/
DEFINE('ROOT', $folder_level);
}

// include configuration file
include(ROOT . 'config.inc.php');

// include headers
include(ROOT . 'common/global.inc.php');

?
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN 
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;
html xmlns=http://www.w3.org/1999/xhtml;
xmlns:v=urn:schemas-microsoft-com:vml 
head
title?php echo $siteTitle ? - ?php echo $pageTitle  ?/title
meta http-equiv=Content-Type content=application/xhtml+xml;
charset=utf-8 /
meta name=description content=?php echo $pageDescription ? /
meta name=robots content=index, follow /
link rel=shortcut icon href=?php echo ROOT ?favicon.ico
type=image/x-icon /
?php include(ROOT . 'includes/scripts_' . $pageScripts . '.inc.php') ?

link rel=stylesheet type=text/css href=?php echo ROOT
?lib/style/theme_?php echo $currentStyle; ?.css /
link rel=stylesheet type=text/css href=?php echo ROOT
?lib/style/layout.css /
link rel=stylesheet type=text/css href=?php echo ROOT
?lib/style/notify.css /
!--[if lt IE 7]
style media=screen type=text/css
.col1 {
width:100%;
}
/style
![endif]--
/head
body
?php include(ROOT . 'includes/XFBML.inc.php') ?
div id=header
?php include(ROOT . 'includes/header.inc.php') ?
ul
?php
$result = $db-query('SELECT * FROM `links` WHERE `category` =
\'primary_navigation\'');

while ($listitem = $db-fetch_array($result))
{
echo \t . 'lia href=' . $listitem['href'] . '';
if (!empty($listitem['class']))
{
if (strtolower($listitem['text']) == strtolower($pageTitle))
{
echo ' class=' . $listitem['class'] . ' active';
}
else
{
echo ' class=' . $listitem['class'] . '';
}
}
echo '' . $listitem['text'] . '/a/li' . \n;
}
?
/ul
p id=layoutdimsnbsp;/p
/div
div class=colmask holygrail
div class=colmid
div class=colleft
div class=col1wrap
div class=col1
!-- Column 1 start - center --
?php
$result_1 = $db-query('SELECT * FROM `directories`
WHERE `id`=' . $pageFolder);
$row_1 = $db-fetch_row($result_1);
$folder_url = $row_1[2];
include(ROOT . $folder_url . 'content/' . $pageName
. '.inc.php'); # content/Homepage.inc.php
?
!-- Column 1 end --
/div
/div
div class=col2
!-- Column 2 start - left --
?php
if (!empty($pageComponentsLeft))
{
$result = $db-query('SELECT * FROM `components`
WHERE `id` IN (' . $pageComponentsLeft . ');');
$count = $db-affected_rows;
$i = 1;

if ($count  0)
{
while ($row = $db-fetch_array($result))
{
require_once($row['url']);
if ($i  $count)
{
echo \n . 'br /' . \n;
}

$i++;
}
}
}
?
pThe CSS used for this layout is 100% valid and hack free.
To overcome Internet Explorer's broken box model, no horizontal padding or
margins are used. Instead, this design uses pixel widths and clever relative

Re: [PHP] Open Source CMS

2010-01-20 Thread Allen McCabe
I suppose I am opposed to 'custom systems' with PHP. I feel that you
shouldn't have to learn new-stuff that is specific to a certain system if
it is so extensive. I know, I'm lazy, but I've been trying to learn PHP (as
well as needing to learn JavaScript, SQL, and CSS 2.0 lately) and not stuff
that will only work in a closed system.

That said; Drupal is VERY powerful, and VERY convenient given the
multi-lingual aspects you (Rob) mentioned. From my angle, achieving what
wanted through Drupal was proving to be almost impossible, when I had a good
idea of how to accomplish it on my own, and figuring out how to integrate
Drupal with my own custom scripts was proving to be a headache for me, so I
ditched Drupal.

Again, Drupal is amazing. I guess what I was trying to say was it depends.
Drupal is great for non-programmers who want to do very simple things, or
for professional PHP programmers who want to do pretty much anything.

Cheers :)

Allen

On Wed, Jan 20, 2010 at 8:14 PM, Robert Cummings rob...@interjinn.comwrote:

 Allen McCabe wrote:

 I've not had much experience with CMS's, however Drupal seems pretty
 featured, with the steep-learning curve; it's not very user friendly.


 Not to disregard your own experience, but I've found Drupal surprisingly
 easy to get running with. In fact it's pretty much my first choice when
 installing a CMS for a client and I demsontrate how simple it is for them to
 add content. This is especially true in Canada where many websites are
 multilingual and Drupal offers one of the best interfaces for providing
 multilingual content. Additionally, the ability to create custom content
 types while possibly difficult for clients to grasp, is really simple for
 them to use if I do the legwork of creating the content types and associated
 views.

 Cheers,
 Rob.
 --
 http://www.interjinn.com
 Application and Templating Framework for PHP



[PHP] Call to undefined method on class property!?

2010-01-07 Thread Allen McCabe
I have a singleton database object in a global file at the top of my
document. In most other locations I am able to access it just fine, however
in my footer I want to loop through a properties list for links (I am saving
links to a database, each with its own properties).

Here is the code snippet that is giving me trouble:

footerlinks.inc.php:

?php
$result = $db-query('SELECT * FROM `links` WHERE `category` =
\'footer_navigation\';');
$total = $db-affected_rows;

if ($total  0)
{
$Link = new Link();
$count = $db-affected_rows($result);
$i = 0;
while ($row = $db-fetch_array($result))
{
$properties = $Link-setLinkProperties($row);

$link[$i] = 'a ';
foreach ($properties as $prop)
{
$link[$i] .= $prop;
}
$link[$i] .= '';
$row['text'];
$link[$i] .= '/a';

$i++;
}

$j = 0;
while ($j  $link)
{
echo $link[$j];
if ($j  $count)
{
echo ' | ';
}

$j++;
}

}

?

The $Link-$Link-setLinkProperties() method is defined in

Link.class.php:

?php

class Link {

public function setLinkProperties($rows)
{
if (!empty($row['href']))
{
$properties['href'] = 'href=' . $row['href'] . ' ';
}

if (!empty($row['class']))
{
$properties['class'] = 'class=' . $row['class'] . ' ';
}

if (!empty($row['style']))
{
$properties['style'] = 'style=' . $row['style'] . ' ';
}

if (!empty($row['title']))
{
$properties['title'] = 'title=' . $row['title'] . ' ';
}

if (!empty($row['name']))
{
$properties['name'] = 'name=' . $row['name'] . ' ';
}

if (!empty($row['target']))
{
$properties['target'] = 'target=' . $row['target'] . ' ';
}

if (!empty($row['rel']))
{
$properties['rel'] = 'rel=' . $row['rel'] . ' ';
}

if (!empty($row['onclick']))
{
$properties['onclick'] = 'onclick=' . $row['onclick'] . ' ';
}

if (!empty($row['ondblclick']))
{
$properties['ondblclick'] = 'ondblclick=' . $row['ondblclick']
. ' ';
}

if (!empty($row['onmouseover']))
{
$properties['onmouseover'] = 'onmouseover=' .
$row['onmouseover'] . ' ';
}

if (!empty($row['onmouseout']))
{
$properties['onmouseout'] = 'onmouseout=' . $row['onmouseout']
. ' ';
}

return $properties;

} // END OF METHOD setLinkProperties
} // END OF CLASS

?

Also for reference, the method query() in my database class sets a value for
$affected_rows:

Database.class.php:

?php

class Database {

private $server   = ''; //database server
private $user = ''; //database login name
private $pass = ''; //database login password
private $database = ''; //database name
private $pre  = ''; //table prefix

###
//internal info
private $error = '';
private $errno = 0;

//number of rows affected by SQL query
public $affected_rows = 0;

...

?

This is the error I am receiving:

*Fatal error*: Call to undefined method Database::affected_rows() in *
/home/mwclans1/public_html/components/footerlinks.inc.php* on line *9*

Please help PHP gurus!!


Re: [PHP] Call to undefined method on class property!? - [CLOSED]

2010-01-07 Thread Allen McCabe
I caught that error, but the line number was referring to the assignment, it
didn't even get to the obvious error.

Why would  $total = $db-affected_rows, (assigning the value of
$affected_rows to $total) be interpreted as a method call?

I have since defined a num_rows() method (using mysql_num_rows()) and I have
gotten past this error, however I am still having a major problem with what
I'm trying to accomplish.

I'll post more later tonight when I get home from work... Thanks for your
help Thijs adn Darren

On Thu, Jan 7, 2010 at 3:49 AM, Thijs Lensselink d...@lenss.nl wrote:

 Allen McCabe wrote:

 I have a singleton database object in a global file at the top of my
 document. In most other locations I am able to access it just fine,
 however
 in my footer I want to loop through a properties list for links (I am
 saving
 links to a database, each with its own properties).

 Here is the code snippet that is giving me trouble:

 footerlinks.inc.php:

 ?php
$result = $db-query('SELECT * FROM `links` WHERE `category` =
 \'footer_navigation\';');
$total = $db-affected_rows;


 Here you use affected_rows as a class property to assign a value to a
 variable.



if ($total  0)
{
$Link = new Link();
$count = $db-affected_rows($result);


 Here you call affected_rows as a class method. And from looking at your
 Database class. affected_rows is a property not a method. So that explains
 the undefined method error.



 $i = 0;
while ($row = $db-fetch_array($result))
{
$properties = $Link-setLinkProperties($row);

$link[$i] = 'a ';
foreach ($properties as $prop)
{
$link[$i] .= $prop;
}
$link[$i] .= '';
$row['text'];
$link[$i] .= '/a';

$i++;
}

$j = 0;
while ($j  $link)
{
echo $link[$j];
if ($j  $count)
{
echo ' | ';
}

$j++;
}

}

?

 The $Link-$Link-setLinkProperties() method is defined in

 Link.class.php:

 ?php

 class Link {

public function setLinkProperties($rows)
{
if (!empty($row['href']))
{
$properties['href'] = 'href=' . $row['href'] . ' ';
}

if (!empty($row['class']))
{
$properties['class'] = 'class=' . $row['class'] . ' ';
}

if (!empty($row['style']))
{
$properties['style'] = 'style=' . $row['style'] . ' ';
}

if (!empty($row['title']))
{
$properties['title'] = 'title=' . $row['title'] . ' ';
}

if (!empty($row['name']))
{
$properties['name'] = 'name=' . $row['name'] . ' ';
}

if (!empty($row['target']))
{
$properties['target'] = 'target=' . $row['target'] . ' ';
}

if (!empty($row['rel']))
{
$properties['rel'] = 'rel=' . $row['rel'] . ' ';
}

if (!empty($row['onclick']))
{
$properties['onclick'] = 'onclick=' . $row['onclick'] . ' ';
}

if (!empty($row['ondblclick']))
{
$properties['ondblclick'] = 'ondblclick=' . $row['ondblclick']
 . ' ';
}

if (!empty($row['onmouseover']))
{
$properties['onmouseover'] = 'onmouseover=' .
 $row['onmouseover'] . ' ';
}

if (!empty($row['onmouseout']))
{
$properties['onmouseout'] = 'onmouseout=' . $row['onmouseout']
 . ' ';
}

return $properties;

} // END OF METHOD setLinkProperties
 } // END OF CLASS

 ?

 Also for reference, the method query() in my database class sets a value
 for
 $affected_rows:

 Database.class.php:

 ?php

 class Database {

private $server   = ''; //database server
private $user = ''; //database login name
private $pass = ''; //database login password
private $database = ''; //database name
private $pre  = ''; //table prefix

###
//internal info
private $error = '';
private $errno = 0;

//number of rows affected by SQL query
public $affected_rows = 0;

 ...

 ?

 This is the error I am receiving:

 *Fatal error*: Call to undefined method Database::affected_rows() in *
 /home/mwclans1/public_html/components/footerlinks.inc.php* on line *9*

 Please help PHP gurus!!





[PHP] Regexp and Arrays

2010-01-02 Thread Allen McCabe
I have been plauged for a few days by this, can anyone see a problem with
this function??

function printByType($string, $mode)
 {
  (string) $string;
  $lengths = array(
'VARCHAR' = 10
, 'TINYINT' = 1
, 'TEXT' = 10
, 'DATE' = 7
, 'SMALLINT' = 1
, 'MEDIUMINT' = 2
, 'INT' = 2
, 'BIGINT' = 3
, 'FLOAT' = 4
, 'DOUBLE' = 4
, 'DECIMAL' = 4
, 'DATETIME' = 10
, 'TIMESTAMP' = 10
, 'TIME' = 7
, 'YEAR' = 4
, 'CHAR' = 7
, 'TINYBLOB' = 10
, 'TINYTEXT' = 10
, 'BLOB' = 10
, 'MEDIUMBLOB' = 10
, 'MEDIUMTEXT' = 10
, 'LONGBLOB' = 10
, 'LONGTEXT' = 10
, 'ENUM' = 5
, 'SET' = 5
, 'BIT' = 2
, 'BOOL' = 1
, 'BINARY' = 10
, 'VARBINARY' = 10);
  $types = array(
'VARCHAR' = 'text'
, 'TINYINT' = 'text'
, 'TEXT' = 'textarea'
, 'DATE' = 'text'
, 'SMALLINT' = 'text'
, 'MEDIUMINT' = 'text'
, 'INT' = 'text'
, 'BIGINT' = 'text'
, 'FLOAT' = 'text'
, 'DOUBLE' = 'text'
, 'DECIMAL' = 'text'
, 'DATETIME' = 'text'
, 'TIMESTAMP' = 'text'
, 'TIME' = 'text'
, 'YEAR' = 'text'
, 'CHAR' = 'text'
, 'TINYBLOB' = 'textarea'
, 'TINYTEXT' = 'textarea'
, 'BLOB' = 'textarea'
, 'MEDIUMBLOB' = 'textarea'
, 'MEDIUMTEXT' = 'textarea'
, 'LONGBLOB' = 'textarea'
, 'LONGTEXT' = 'textarea'
, 'ENUM' = 'text'
, 'SET' = 'text'
, 'BIT' = 'text'
, 'BOOL' = 'text'
, 'BINARY' = 'text'
, 'VARBINARY' = 'text');

  switch ($mode)
  {
   case 'INPUT_LENGTH':
foreach ($lengths as $key = $val)
{
 (string) $key;
 (int) $val;

 // DETERMINE LENGTH VALUE eg. int(6) GETS 6
 preg_match('#\((.*?)\)#', $string, $match);
 (int) $length_value = $match[1];

 // SEARCH
 $regex = / . strtolower($key) . /i;
 $found = preg_match($regex, $string);

 if ($found !== false)
 {
  // DETERMINE ADD INTEGER eg. If the length_value is long enough,
determine number to increase html input length
  switch ($length_value)
  {
   case ($length_value = 7):
return $length_value;
   break;
   case ($length_value  7  $length_value  15):
return $val += ($length_value/2);
   break;
   case ($length_value  14  $length_value  101):
$result = ($length_value / 5);
$divide = ceil($result);
return $val += $divide;
   break;
   case ($length_value  100):
return 40;
   break;
   default:
return 7;
   break;
  }
  return $val;
 }
 else
 {
  return 7; // default value
 }
}
   break;

   case 'INPUT_TYPE':

foreach ($types as $key = $val)
{
 (string) $val;
 (string) $key;

 // SEARCH
 $regex = / . strtolower($key) . /i;
 $found = preg_match($regex, $string);

 if ($found === false)
 {
  return 'text'; // default value
 }
 else
 {
  return $val;
 }
}
   break;
  }

 } // END function printByType()


Re: [PHP] Regexp and Arrays

2010-01-02 Thread Allen McCabe
I think part of the problem may lie in the use of variables in regular
expressions. I am trying to use the perl-style preg_match(), but the regular
expression values that it checks on each iteration of the foreach loop
checks for a different value (hence, the use of a variable).

On Sat, Jan 2, 2010 at 1:19 PM, shiplu shiplu@gmail.com wrote:

 There can be a problem. But do you see a problem?? if yes. what is it?
 May be we can find the solution.

 --
 Shiplu Mokaddim
 My talks, http://talk.cmyweb.net
 Follow me, http://twitter.com/shiplu
 SUST Programmers, http://groups.google.com/group/p2psust
 Innovation distinguishes bet ... ... (ask Steve Jobs the rest)



[PHP] Arrays Regexp - Help Requested

2010-01-01 Thread Allen McCabe
Happy New Year, here's my first question of the year (and it's only 15 hours
into the year!).

I am creating a small database management tool for my a website (my work IP
blocks my access to PhpMyAdmin) and I don't want to install any additional
software.

I am working on adding rows and need to format the input boxes properly (ie.
VARCHAR needs an text input, TEXT needs a textarea input). Using a mysql
query I can determine the data types for each field. I have a function that
uses this information to return datatype specific variables. For example
$field['field'] may equal int(6) or varchar(256).

The code is a bit extensive, but it's necessary to explain what's going on.

?php
// Loop:
echo 'table width=100% cellspacing=1 cellpadding=2 border=0' .
\n;
foreach ($fields as $field)
{
 // ROW BEGIN
 echo \t . 'tr' . \n;
 // NAME OF FIELD
 echo \t\t . 'td`' . $field['field'] . '`: /td' . \n;
 // FIELD DATA TYPE
 echo \t\t . 'td' . $field['type'] . '/td' . \n;
 // VALUE INPUT
 echo \t\t . 'td';
 $input_type = printByType($field['type'], 'INPUT_TYPE');
 echo 'input type=' . $input_type . ' ';
 if ($input_type == 'text')
 {
  echo 'size=';
  $length = printByType($field['type'], 'INPUT_LENGTH');
  echo $length;
  echo ' ';
  echo 'value=';
  if ($field['null'] == 'YES') // CAN BE NULL?
  {
   echo 'NULL';
  }
  echo ' ';
 }
 elseif ($input_type == 'textarea')
 {
  echo 'rows=7 cols=30 ';
  echo 'value=';
  if ($field['null'] == 'YES') // CAN BE NULL?
  {
   echo 'NULL';
  }
  echo ' ';
 }
 echo 'name=value[] id=value[]
onfocus=if(this.value==\'NULL\')this.value=\'\'; /';
 echo '/td' . \n;
 echo \t . '/tr' . \n;
}
echo '/table';

?

The function:

?php

function printByType($string, $mode)
 {
  (string) $string;
  $lengths = array(
'VARCHAR' = 10
, 'TINYINT' = 1
, 'TEXT' = 10
, 'DATE' = 7
, 'SMALLINT' = 1
, 'MEDIUMINT' = 2
, 'INT' = 2
, 'BIGINT' = 3
, 'FLOAT' = 4
, 'DOUBLE' = 4
, 'DECIMAL' = 4
, 'DATETIME' = 10
, 'TIMESTAMP' = 10
, 'TIME' = 7
, 'YEAR' = 4
, 'CHAR' = 7
, 'TINYBLOB' = 10
, 'TINYTEXT' = 10
, 'BLOB' = 10
, 'MEDIUMBLOB' = 10
, 'MEDIUMTEXT' = 10
, 'LONGBLOB' = 10
, 'LONGTEXT' = 10
, 'ENUM' = 5
, 'SET' = 5
, 'BIT' = 2
, 'BOOL' = 1
, 'BINARY' = 10
, 'VARBINARY' = 10);
  $types = array(
'VARCHAR' = 'text'
, 'TINYINT' = 'text'
, 'TEXT' = 'textarea'
, 'DATE' = 'text'
, 'SMALLINT' = 'text'
, 'MEDIUMINT' = 'text'
, 'INT' = 'text'
, 'BIGINT' = 'text'
, 'FLOAT' = 'text'
, 'DOUBLE' = 'text'
, 'DECIMAL' = 'text'
, 'DATETIME' = 'text'
, 'TIMESTAMP' = 'text'
, 'TIME' = 'text'
, 'YEAR' = 'text'
, 'CHAR' = 'text'
, 'TINYBLOB' = 'textarea'
, 'TINYTEXT' = 'textarea'
, 'BLOB' = 'textarea'
, 'MEDIUMBLOB' = 'textarea'
, 'MEDIUMTEXT' = 'textarea'
, 'LONGBLOB' = 'textarea'
, 'LONGTEXT' = 'textarea'
, 'ENUM' = 'text'
, 'SET' = 'text'
, 'BIT' = 'text'
, 'BOOL' = 'text'
, 'BINARY' = 'text'
, 'VARBINARY' = 'text');

  switch ($mode)
  {
   case 'INPUT_LENGTH':
foreach ($lengths as $key = $val)
{
 (string) $key;
 (int) $val;

 // DETERMINE LENGTH VALUE eg. int(6) GETS 6
 preg_match('#\((.*?)\)#', $string, $match);
 (int) $length_value = $match[1];

 // SEARCH
 $regex = / . strtolower($key) . /i;
 $found = preg_match($regex, $string);

 if ($found !== false)
 {
  // DETERMINE ADD INTEGER eg. If the length_value is long enough,
determine number to increase html input length
  switch ($length_value)
  {
   case ($length_value = 7):
return $length_value;
   break;
   case ($length_value  7  $length_value  15):
return $val += ($length_value/2);
   break;
   case ($length_value  14  $length_value  101):
$result = ($length_value / 5);
$divide = ceil($result);
return $val += $divide;
   break;
   case ($length_value  100):
return 40;
   break;
   default:
return 7;
   break;
  }
  return $val;
 }
 else
 {
  return 7; // default value
 }
}
   break;

   case 'INPUT_TYPE':

foreach ($types as $key = $val)
{
 (string) $val;
 (string) $key;

 // SEARCH
 $regex = / . strtolower($key) . /i;
 $found = preg_match($regex, $string);

 if ($found === false)
 {
  return 'text'; // default value
 }
 else
 {
  return $val;
 }
}
   break;
  }

 }

?

The first part of the function (the first switch case) works, and the text
fields are variable in length, but even the fields with a TEXT datatype is
printing out a text box instead of a textarea. Can anyone see why this is
happening?

Thanks!


[PHP] Accessing Objects - Object to Object Communication

2009-12-26 Thread Allen McCabe
I have a Database class that I instantiate with credential information. The
connect method connects and creates a resource by the name $link_id. So if I
do this:

$db = new Database($server, $user, $password, $database);
$db-connect();

To get the resource (for use by mysql_insert_id() for example), I use
$db-link_id, so to get the last inserted record:
$id = mysql_insert_id($db-link_id);

Now for my question:

I have another class for creating pages (content). I have a method called
newPage() that accepts 4 arguments: title, content, role_id, display, and
description.

If I need to get the ID of this new page (which is inserted to a mysql table
with an id field with auto_increment), how would I access my database
object? Here is what I have, but first I should provide a brief explanation:
I am trying to pass the database object to any other object that needs to
access the database so that I am assured a connection exists before using
any query methods. So instead of  Database::query($sql), I have
$this-db-query($sql).

Here are some code snippets:

Content.class.php:
class Page {

private $db;// Contains reference to instance of the
Database class
private $notify;// Contains reference to instance of the
Notifier class
private $URL;

public function __construct($dbconnection, $root, $id = null)
{
$this-db = $dbconnection;
$this-notify = Notifier::getInstance();
$this-URL = $root . 'content/';

if (isset($id)) {
$result = $this-db-query('SELECT * FROM `content` WHERE
`page_id` = \''. $id .'\'');
$data = $this-db-fetch_array($result);
}
}
}

header.php:
require_once('lib/class/Database.class.php');
$db = new Database($dbhost, $dbuser, $dbpass, $dbname);
$db-connect();
require_once('lib/class/Notifier.class.php');
$notify = Notifier::getInstance(); // self instantiates
require_once('lib/class/Content.class.php');
$page = new Page($db, ROOT);


Does this look right? I don't think I've ever seen two - operators together
like this before...

I don't want to keep connecting to the database, and more importantly, my
Notifier class should only be a single instance, so I need to be able to
amend to a static array variable in that class from within other classes.

Thanks for any help you can provide, and happy holidays!


Re: [PHP] Form validation issue

2009-12-24 Thread Allen McCabe
Tedd,

If you are using a post method using $_SERVER['PHP_SELF'], then values are
present in the POST array, hence, you would write your html with
interspersed php like so:

input type=text name=username value=?php if
(isset($_POST['username'])) echo $_POST['username'] ? id=username /

I sometimes use a function for the echoing of these values if I use the same
form for first time (ie. registration) and editing (update), and the
function checks for a $_POST value, then secondly for an existing database
value variable (ie. $row['username']). If either exist, populate the input
with it (precedence given to POST), otherwise it is empty.

The function looks something this:

function echoValue($post=null, $row=null) {
if (isset($post)) {
echo $post;
} elseif (isset($row)) {
echo $row;
}
}

and is used like this:

input type... value=?php echoValue($_POST['username'], $row['username'] )
? id=username /

after performing a query on a query-string variable (eg. profile.php?id=57
--- 'SELECT * FROM `users` WHERE `id` = '.$_GET['id'] ) etc.

On Mon, Dec 21, 2009 at 8:03 AM, tedd tedd.sperl...@gmail.com wrote:

 At 9:43 PM -0500 12/20/09, Ernie Kemp wrote:

 Good Day,

I need help in in validating a form.
The for is valdated be a javascript frist then if all the
 fields are filled in its valaded be PHP.

The Form starts with:
form name=myForm action=?php echo
 $_SERVER['PHP_SELF'];? method=post onsubmit='return formValidator()' 

 The formValidator() goes to a javascript and does display the missing
 information in this case BUT then the page gets reloaded and clears all the
 javascript error messages and does the PHP validation.

 The PHP only runs if the fields are set by testing using 'isset.

 Without puting on numeric lines of go can you suggest things I must have
 overlooked. Silly request but there must be something I'm overlooking.I
 have simular code on other programs but this one is casuing me trouble.

 Thanks every so much..



 Ernie:

 Client-side javascript can help populate fields and correct any problems a
 user might have, but once the form is submitted to the server, then the data
 is sent and evaluated server-side, hence validation.

 However, if the server-side evaluation fails and the page is refreshed,
 then all the previous values are lost -- UNLESS -- you keep them in a
 cookie, database, or session. I suggest using a session.

 Cheers,

 tedd

 --
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com

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




[PHP] Logic of conditionals and the ( ) operators

2009-12-18 Thread Allen McCabe
In a nutshell:

Will this work?

if ($perm == (11 || 12))


Explanation:

I am laying the groundwork for a photo viewing system with a private and
public mode, and additionally if an admin is logged in, there is an
additional level of permission. I came up with a number system to make it
easier (and is calcualted by a class) so now, instead of checking against
the $mode variable, if the user is logged in, and then what their user level
is if they are logged in, I just check against some numbers (the class
evaluates all those conditions and assigns the appropriate number a single
permission variable, $perm.


Re: [PHP] Logic of conditionals and the ( ) operators (RESOLVED)

2009-12-18 Thread Allen McCabe
Thank you Ashley, it makes perfect sense. I don't know why I didn't just set
up some tests like Shiplu suggested!

I've rewritten all my code BACK to the correct way. (I thought it looked
cooler, oh well).

On Fri, Dec 18, 2009 at 10:47 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

   On Fri, 2009-12-18 at 10:21 -0800, Allen McCabe wrote:

 In a nutshell:

 Will this work?

 if ($perm == (11 || 12))


 Explanation:

 I am laying the groundwork for a photo viewing system with a private and
 public mode, and additionally if an admin is logged in, there is an
 additional level of permission. I came up with a number system to make it
 easier (and is calcualted by a class) so now, instead of checking against
 the $mode variable, if the user is logged in, and then what their user level
 is if they are logged in, I just check against some numbers (the class
 evaluates all those conditions and assigns the appropriate number a single
 permission variable, $perm.


 That equates to if($perm == true) as 11 in this case translates to true
 (being a positive integer) The code never needs to figure out the || part,
 as the first part is true.

 I think what you'd want to do is possibly:

 if($perm == 11 || $perm == 12)

   Thanks,
 Ash
 http://www.ashleysheridan.co.uk





Re: [PHP] Class not functioning (RESOLVED)

2009-12-18 Thread Allen McCabe
I looked into registries (singleton registries), and while I can see the
advantage they provide, most every article I read advised AGAINST using
singleton registries because it creates extra dependencies (ie. a file needs
the database class AND the registry class instead of just the database
class). The disadvantage to me about this is having to keep everything
straight; my projects as of late have been expanding rapidly and I can
barely keep track of everything. As it stands, it takes me about 30 minutes
to get back into my projects each day.

Wouter; I ended up going with the static option and it works nicely :) I am
thrilled at how it just works! Coupled with some nicely styled DIV layers
and some onclick=this.style.display='none'; to make it go away I have a
fantastic user notification system.

On Wed, Dec 16, 2009 at 3:59 AM, Wouter van Vliet / Interpotential 
pub...@interpotential.com wrote:

 Allen,

 Before you go with my static-approach, please do consider Shawn's registry
 pattern suggestion. That's pretty sweet too ;-).

 A little response to your long text, before I help you fix the bug. A
 static property is basically the same as a regular property on an object.
 Only difference is that they are not reset when the class is instantiated
 into an object. They are just there.

 Now, about your bug. The syntax for referencing a static property is a bit
 weird - which has to do with the existence of class constants, which might
 have set you off.

 Notifier::notifyQueue would reference a class constant. The [] syntax is
 not valid here, since a constant is - you got it: constant. And thus cannot
 be changed.
 Notifier::$notifyQ[] = 'div ... /div'; references the static property.

 But... since notifyQ is a proptected static property, it is very unlikealy
 that you'll ever actually write Notifier::$notifyQ. You add to this queue
 from within the class itself, so therefore self::$notifyQ is a lot better.

 Does that answer your question?

 Btw; Shawn; Assuming that your Registry class holds objects, there is no
 need have the ampersand in front of the get method or $object argument.
 Objects are *always* references. And you might want to look at the __get,
 __set and __isset magic.

 Wouter


 2009/12/16 Allen McCabe allenmcc...@gmail.com

 Wouter,

 Implementing your static idea was pretty easy, I was already referencing
 Notifier with the :: operator in my other methods, however I am running into
 trouble assigning new values to the static array.

 I am getting a syntax error, unexpected '['  on this line of my Notifier
 class:

 Notifier::notifyQ[] = 'div class='.$message;

 . . .

 Any ideas why this is causing an error?
 (note: I did try using $this-Notifier, and it said I cannot do what-not
 to a non-object, can't remember the exact message at the moment)

 On Tue, Dec 15, 2009 at 2:30 PM, Wouter van Vliet / Interpotential 
 pub...@interpotential.com wrote:

 Allen,

 The short answer (but don't follow this):
 ?php
 class Meetgreet {
   public function deleteSingle($id, $number) {
   // do something
   global $Notify;
   $Notify-addToQ( .. );
   }
 }
 ?

 The long(er) answer:
 I assume your Notifier object functions as singleton? Ie; accross your
 entire application, there is only one instance of that class?

 Why not go-static? That is, to my experience, the sweetest way to make
 something globally accessible - without making something global. Like so

 ?php
 class Notifier {

protected static $queue = Array();

// make sure it can't be instantiated
private constructer __construct() {
}

public static function addToQ( $arg, $anotherArg) {
self::$queue[] = $arg.' - '.$anotherArg;
}

 }

 // and then from within any method anywhere, call
 Notifier::addToQ('foo', 'bar');

 ?

 Does that work for you?

 Regards,
 Wouter

 (ps. call me a purist, but a function defined in a class is no longer
 called a function, but a *method*)

 2009/12/15 Allen McCabe allenmcc...@gmail.com

  Hey all (and Nirmalya, thanks for the help!),


 I have a question that I just can't seem to find via Google.

 I want to be able to add messages to a qeue whenever my classes complete
 (or
 fail to complete) specific functions. I think have a call within my html
 to
 my Notifier class to print all qeued messages (via a function 'printQ').

 How do I access a globally instantiated class from within another class?

 Example:

 ?php

 // INSTANTIATE
 $Meetgreet = new Meetgreet;
 $Notify = new Notifier;

 ...
 ...

 $Meetgreet-deleteSingle($id, 1); // This completes a function within
 Meetgreet class. That function needs to be able to use the Notifier
 function
 addtoQ(), how would this be accomplished?

 ?
 ...
 ...

 ?php  $Notify-printQ()  ?

 On Mon, Dec 14, 2009 at 6:07 PM, Nirmalya Lahiri
 nirmalyalah...@yahoo.comwrote:

  --- On Tue, 12/15/09, Allen McCabe allenmcc...@gmail.com wrote:
 
   From: Allen McCabe allenmcc...@gmail.com
   Subject: [PHP] Class not functioning

Re: [PHP] Class not functioning

2009-12-15 Thread Allen McCabe
Hey all (and Nirmalya, thanks for the help!),


I have a question that I just can't seem to find via Google.

I want to be able to add messages to a qeue whenever my classes complete (or
fail to complete) specific functions. I think have a call within my html to
my Notifier class to print all qeued messages (via a function 'printQ').

How do I access a globally instantiated class from within another class?

Example:

?php

// INSTANTIATE
$Meetgreet = new Meetgreet;
$Notify = new Notifier;

...
...

$Meetgreet-deleteSingle($id, 1); // This completes a function within
Meetgreet class. That function needs to be able to use the Notifier function
addtoQ(), how would this be accomplished?

?
...
...

?php  $Notify-printQ()  ?

On Mon, Dec 14, 2009 at 6:07 PM, Nirmalya Lahiri
nirmalyalah...@yahoo.comwrote:

 --- On Tue, 12/15/09, Allen McCabe allenmcc...@gmail.com wrote:

  From: Allen McCabe allenmcc...@gmail.com
  Subject: [PHP] Class not functioning
  To: phpList php-general@lists.php.net
  Date: Tuesday, December 15, 2009, 6:17 AM
   Hey everyone, I just delved into
  classes recently and have been having
  moderate success so far.
 
  I have a puzzler though.
 
  I have the following class decalred and instantiated:
 
  class Notify {
   var $q = array();
 
   public function addtoQ($string, $class)
   {
$message = 'span class='. $class .''.
  $string .'/span';
$this-q[] = $message;
   }
 
   public function printQ()
   {
if (isset($q))
{
 echo 'p align=center
  class=notification';
 foreach($this-q as $msg)
 {
  echo $msg .\n;
 }
 echo '/p';
}
 
return;
   }
 
   function __destruct()
   {
if (isset($q))
{
 unset($this-q);
}
   }
  } // END CLASS Notify
 
 
  And in my script, I call it like so:
  $Notif = new Notify;
 
  I have run other statements in other classes that should be
  adding to the $q
  array (ie. Notify::addtoQ('ERROR! There Was An Error
  Updating The
  Database!', 'error');)
 
  However, when I try to get my webpage to display them
  using:
 
  $Notify-printQ();
 
  it does not seem to want to loop through this array (and
  print the
  messages). I am getting NO error message, in fact
  everything 'looks' fine,
  I'm just not seeing the appropriate message.
 
  Any help would be appreicated!
 

 Allen,
  You have made a small typing mistake in function printQ() where you would
 like to checked the array for its existence. By mistake you have wrote if
 (isset($q)). But your array variable is not an freely accessible array,the
 array is embedded into an object. So, you have to write the like if
 (isset($this-q)).

  Another point, you can't add a message into the array by calling the
 member function addtoQ() using scope resolution operator ::. If you really
 want to add message into the array, you have to call the member function
 from within the object. (ie. $Notif-addtoQ('ERROR! There Was An Error
 Updating The Database!', 'error');).

 ---
 নির্মাল্য লাহিড়ী [Nirmalya Lahiri]
 +৯১-৯৪৩৩১১৩৫৩৬ [+91-9433113536]







Re: [PHP] Class not functioning

2009-12-15 Thread Allen McCabe
Wouter,

Implementing your static idea was pretty easy, I was already referencing
Notifier with the :: operator in my other methods, however I am running into
trouble assigning new values to the static array.

I am getting a syntax error, unexpected '['  on this line of my Notifier
class:

Notifier::notifyQ[] = 'div class='.$message;

. . .

Any ideas why this is causing an error?
(note: I did try using $this-Notifier, and it said I cannot do what-not to
a non-object, can't remember the exact message at the moment)

On Tue, Dec 15, 2009 at 2:30 PM, Wouter van Vliet / Interpotential 
pub...@interpotential.com wrote:

 Allen,

 The short answer (but don't follow this):
 ?php
 class Meetgreet {
   public function deleteSingle($id, $number) {
   // do something
   global $Notify;
   $Notify-addToQ( .. );
   }
 }
 ?

 The long(er) answer:
 I assume your Notifier object functions as singleton? Ie; accross your
 entire application, there is only one instance of that class?

 Why not go-static? That is, to my experience, the sweetest way to make
 something globally accessible - without making something global. Like so

 ?php
 class Notifier {

protected static $queue = Array();

// make sure it can't be instantiated
private constructer __construct() {
}

public static function addToQ( $arg, $anotherArg) {
self::$queue[] = $arg.' - '.$anotherArg;
}

 }

 // and then from within any method anywhere, call
 Notifier::addToQ('foo', 'bar');

 ?

 Does that work for you?

 Regards,
 Wouter

 (ps. call me a purist, but a function defined in a class is no longer
 called a function, but a *method*)

 2009/12/15 Allen McCabe allenmcc...@gmail.com

  Hey all (and Nirmalya, thanks for the help!),


 I have a question that I just can't seem to find via Google.

 I want to be able to add messages to a qeue whenever my classes complete
 (or
 fail to complete) specific functions. I think have a call within my html
 to
 my Notifier class to print all qeued messages (via a function 'printQ').

 How do I access a globally instantiated class from within another class?

 Example:

 ?php

 // INSTANTIATE
 $Meetgreet = new Meetgreet;
 $Notify = new Notifier;

 ...
 ...

 $Meetgreet-deleteSingle($id, 1); // This completes a function within
 Meetgreet class. That function needs to be able to use the Notifier
 function
 addtoQ(), how would this be accomplished?

 ?
 ...
 ...

 ?php  $Notify-printQ()  ?

 On Mon, Dec 14, 2009 at 6:07 PM, Nirmalya Lahiri
 nirmalyalah...@yahoo.comwrote:

  --- On Tue, 12/15/09, Allen McCabe allenmcc...@gmail.com wrote:
 
   From: Allen McCabe allenmcc...@gmail.com
   Subject: [PHP] Class not functioning
   To: phpList php-general@lists.php.net
   Date: Tuesday, December 15, 2009, 6:17 AM
Hey everyone, I just delved into
   classes recently and have been having
   moderate success so far.
  
   I have a puzzler though.
  
   I have the following class decalred and instantiated:
  
   class Notify {
var $q = array();
  
public function addtoQ($string, $class)
{
 $message = 'span class='. $class .''.
   $string .'/span';
 $this-q[] = $message;
}
  
public function printQ()
{
 if (isset($q))
 {
  echo 'p align=center
   class=notification';
  foreach($this-q as $msg)
  {
   echo $msg .\n;
  }
  echo '/p';
 }
  
 return;
}
  
function __destruct()
{
 if (isset($q))
 {
  unset($this-q);
 }
}
   } // END CLASS Notify
  
  
   And in my script, I call it like so:
   $Notif = new Notify;
  
   I have run other statements in other classes that should be
   adding to the $q
   array (ie. Notify::addtoQ('ERROR! There Was An Error
   Updating The
   Database!', 'error');)
  
   However, when I try to get my webpage to display them
   using:
  
   $Notify-printQ();
  
   it does not seem to want to loop through this array (and
   print the
   messages). I am getting NO error message, in fact
   everything 'looks' fine,
   I'm just not seeing the appropriate message.
  
   Any help would be appreicated!
  
 
  Allen,
   You have made a small typing mistake in function printQ() where you
 would
  like to checked the array for its existence. By mistake you have wrote
 if
  (isset($q)). But your array variable is not an freely accessible
 array,the
  array is embedded into an object. So, you have to write the like if
  (isset($this-q)).
 
   Another point, you can't add a message into the array by calling the
  member function addtoQ() using scope resolution operator ::. If you
 really
  want to add message into the array, you have to call the member function
  from within the object. (ie. $Notif-addtoQ('ERROR! There Was An Error
  Updating The Database!', 'error');).
 
  ---
  নির্মাল্য লাহিড়ী [Nirmalya Lahiri]
  +৯১-৯৪৩৩১১৩৫৩৬ [+91-9433113536]
 
 
 
 
 




 --
 http://www.interpotential.com
 http://www.ilikealot.com

 Phone: +4520371433



[PHP] Class not functioning

2009-12-14 Thread Allen McCabe
Hey everyone, I just delved into classes recently and have been having
moderate success so far.

I have a puzzler though.

I have the following class decalred and instantiated:

class Notify {
 var $q = array();

 public function addtoQ($string, $class)
 {
  $message = 'span class='. $class .''. $string .'/span';
  $this-q[] = $message;
 }

 public function printQ()
 {
  if (isset($q))
  {
   echo 'p align=center class=notification';
   foreach($this-q as $msg)
   {
echo $msg .\n;
   }
   echo '/p';
  }

  return;
 }

 function __destruct()
 {
  if (isset($q))
  {
   unset($this-q);
  }
 }
} // END CLASS Notify


And in my script, I call it like so:
$Notif = new Notify;

I have run other statements in other classes that should be adding to the $q
array (ie. Notify::addtoQ('ERROR! There Was An Error Updating The
Database!', 'error');)

However, when I try to get my webpage to display them using:

$Notify-printQ();

it does not seem to want to loop through this array (and print the
messages). I am getting NO error message, in fact everything 'looks' fine,
I'm just not seeing the appropriate message.

Any help would be appreicated!


[PHP] refuses to complete all queries

2009-12-09 Thread Allen McCabe
I have a PURGE ORDERS link that calculates which orders are made up
entirely of expired shows and deletes them. Well, that's idea anyhow.

The procedure does 3 things:

1. Gets the order_id of all orders that contain all expired shows
2. Deallocates the quantity of the seats on each show from the show table
(freeing up 'inventory')
3. Deletes the order from the order table and all associated entries on the
line_item table.

Well, it does the first step beautifully, but does not want to delete the
table entries. The problem seems to be somewhere in:


// CREATE STRING FROM $black_list[] array
  $expired_order_ids_str = implode($black_list, ', ');

  // UPDATE SHOW QUANTITIES - SUBTRACT SEATS
  $getshowsSQL = SELECT * FROM afy_order_lineitem WHERE order_id IN
({$expired_order_ids_str});
  $showsResult = mysql_query($getshowsSQL);
  while ($updateShow = mysql_fetch_array($showsResult))
  {
   $updatequantitySQL = UPDATE afy_show SET show_seats_reqd =
(show_seats_reqd - {$updateShow['quantity']}) WHERE show_id =
{$updateShow['show_id']};
   $updatequantityResult = mysql_query($updatequantitySQL);
  }
  mysql_free_result($showsResult);

  // UPDATE MYSQL
  $deleteSQL = DELETE FROM afy_order WHERE order_id IN
({$expired_order_ids_str});
  mysql_query($deleteSQL);
  $deleteSQL = DELETE FROM afy_order_lineitem WHERE order_id IN
({$expired_order_ids_str});
  $deleteResult = mysql_query($deleteSQL);
  if ($deleteResult)
  {
   $message = font color=\#009900\Orders successfully Purged!br
/(Order #'s deleted: {$expired_order_ids_str})/font;
  }
  break;

The works just fine, up until the // UPDATE MYSQL line. I am NOT getting the
$message set, and the orders are NOT being deleted. Only the afy_show gets
updated. Can anyone see an problem with this??

Thanks!


[PHP] Filtering results via user input

2009-12-08 Thread Allen McCabe
I wrote a function (inferior no doubt) that takes the values of a form with
a get method to filter results from the database.

It is a list of orders, and I need to be able to filter by the user, the
user's school, or specific items (find all orders that have *this* item).

I thought I figured out how to do it all, but it's just not returning a
'valid resource'.


How do most people go about this? POST or GET? POST is obviously the most
secure, but since this is on an employee only page, security (to my niave
way of thinking) is not much of an issue.

All the filter parameters are from drop downs; I have three forms set up (to
filter by user, school, or item) and I did this because I don't know the
first thing about AJAX (dynamically updating form drop-downs).

If anyone is interested, I would like to send you the PHP file with the
filter function (as it is too long to paste here).

PLEASE HELP!  Thanks :)


[PHP] mysterious include problem

2009-12-07 Thread Allen McCabe
I have been using includes for my content for a while now with no problems.
Suddenly it has stopped working, and it may or may not be from some changes
I made in my code structure.

I use default.php for most or all of my pages within a given directory,
changing the content via page numbers in the query string.


So on default.php, I have the following code:


?php
if(isset($_GET['page']))
{
  $thispage = $_GET['page'];
  $content = 'content/'.$_GET['page'].'.inc';
}
else
{
  $thispage = default;
  $content = 'content/default.inc';
}
?
html, body, div etc.
?php include($content); ?


I have a content subdirectory where I store all the pages with files such as
default.inc, 101.inc, 102.inc, etc.

As I said, this has been working fine up until now, if I use the url
user/default.php or just user/ I get this error:


*Warning*: include(content/.inc)
[function.includehttp://lpacmarketing.hostzi.com/user/function.include]:
failed to open stream: No such file or directory in *
/home/a9066165/public_html/user/default.php* on line *89*

AND

*Warning*: include()
[function.includehttp://lpacmarketing.hostzi.com/user/function.include]:
Failed opening 'content/.inc' for inclusion
(include_path='.:/usr/lib/php:/usr/local/lib/php') in *
/home/a9066165/public_html/user/default.php* on line *89*

But if I use user/default.php?page=default  I get the correct content.

It's acting as if page is set, but set to NULL, and then trying to find an
include at path content/.inc  what's going on??


[PHP] cookies and carts

2009-12-07 Thread Allen McCabe
I have a shopping cart type system set up which keeps track of the cart
contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is
equal to the quantity, so the name/value pair is all the information I need.

But sessions are unreliable on the free server I am currently using for this
website (not my choice), so I had start using cookies because users were
being sporadically logged out, sometimes just on a page refresh.

I want to find a way to set a cookie to remember the cart items as well, and
I thought setting a cookie for each item/quantity pair was the way to go
until I started trying to figure out how to unset all those cookies if the
user empties their cart.

Is there any way to set cookies with an array for the name? Intead of
$_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the
SESSION?


[PHP] SESSIONS classes

2009-11-30 Thread Allen McCabe
I am trying to implement a relatively complete login system code for my
website, but the code is a bit dated ($HTTP_POST_VARS for example).

I am not too familiar with classes and I'm having trouble with this one.

I have an include which is the login form if the SESSION is not set, and a
mini control panel when it is.


I will post the code below because it is a bit extensive. My problem: When I
try to log in (POST username/password to same page and validate with the
class, the page simply reloads MINUS THE FORM SUBMIT BUTTON. It's very odd.
I have a working system on another website without using this class, I just
hoping to be more object-oriented with this one.

Like I said, the code is a bit lengthy, and if you are kind enough to take a
look at I can even send you the php files for the sake of readability (ie.
formatted better than here).



Anything you can help with would be greatly appreciated; I'll have my wife
bake you some cookies or something!

The basic page looks like this:

?php
// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');

// Create an instance of DbConnector
$connector = new DbConnector();

// sets $thispage and $directory
include('../includes/pagedefinition.php');

// Include functions
require_once('../includes/functions.php');

//content
include('../includes/signupform.php');
include('../includes/signup_val_inser_eml.php');
include('../includes/signinform.php');
include('../includes/header.php');
include('../includes/body.php');
?

The page definition file looks like this:

?php
require_once(Sentry.php);
if ($_GET['action'] == 'logout'){
 if ($sentry-logout()){
  echo 'p align=\center\ class=\confirm\You have been logged
out/pbr';
 }
}

. . . // site content-grabbing code excluded ///

// Attempted login url - use for redirect after login.
$redirect = 
http://mwclans.com/{$_SERVER['REQUEST_URI'http://mwclans.com/%7B$_SERVER['REQUEST_URI'
]};
// Defined in includes/Sentry.php
$sentry = new Sentry();
// If logging in, POST['login'] will be set - check credentials (9 is used
to specify the minimum group level that's allowed to access this resource)
if ($_POST['login'] != ''){
 
$sentry-checkLogin($_POST['username'],$_POST['password'],9,'$redirect',/user/index.php');
}
if ($minlevel  9)
{
 if (!$sentry-checkLogin($minlevel) ){ header(Location:
/user/http://www.mwclans.com/user/);
die(); }
}
?

Here is the Sentry class:

?php

// Class: sentry
// Purpose: Control access to pages
///
class sentry {

 var $loggedin = false; // Boolean to store whether the user is logged in
 var $userdata;   //  Array to contain user's data

 function sentry(){
  session_start();
  header(Cache-control: private);
 }

 
//==
 // Log out, destroy session
 function logout(){
  if (is_object($this-userdata))
  {
   unset($this-userdata);
   $session_name = session_name();
   return true;
  }
  else
  {
   $message = p align=\center\ class=\error\Call to non-object by
function: logout()/p;
  }

 }
 
//==
 // Log in, and either redirect to goodRedirect or badRedirect depending on
success
 function checkLogin($username = '',$password = '',$role_id =
9,$goodRedirect = '',$badRedirect = ''){
  // Include database and validation classes, and create objects
  require_once('DbConnector.php');
  require_once('Validator.php');
  $validate = new Validator();
  $loginConnector = new DbConnector();

  // If user is already logged in then check credentials
  if ($_SESSION['username']  $_SESSION['password']){
   // Validate session data
   if (!$validate-validateTextOnly($_SESSION['username'])){return false;}
   if (!$validate-validateTextOnly($_SESSION['password'])){return false;}
   $getUser = $loginConnector-query(SELECT * FROM user WHERE username =
'.$_SESSION['username'].' AND password = '.$_SESSION['password'].' AND
role_id = .$role_id.' AND verified = 1');
   if ($loginConnector-getNumRows($getUser)  0){
// Existing user ok, continue
if ($goodRedirect != '') {
 header(Location: .$goodRedirect.?.strip_tags(session_id())) ;
}
return true;
   }else{
// Existing user not ok, logout
$this-logout();
return false;
   }

  // User isn't logged in, check credentials
  }else{
   // Validate input
   if (!$validate-validateTextOnly($username)){return false;}
   if (!$validate-validateTextOnly($password)){return false;}
   // Look up user in DB
   $getUser = $loginConnector-query(SELECT * FROM user WHERE username =
'$username' AND password = PASSWORD('$password') AND role_id = $role_id AND
verified = 1);
   $this-userdata = $loginConnector-fetchArray($getUser);
   if ($loginConnector-getNumRows($getUser)  0){
// 

[PHP] Storing (html and php) Content in MySQL - help

2009-11-30 Thread Allen McCabe
I have been trying to wrap my mind around how to accomplish this for a few
days, and done estensive searching on Google.

I know there are free CMS systems available for download, but I want to
write my own code so I can maintain it and extend it, I need it to be
customizable.

So far what I have worked up is this:

The mysql row contains a page_id field, title field, content field, and
sidebar content field.

in index.php:
include(module.php)
$username = findLoggedinUsername()

eval ($content)


in module.php:
$result = mysqlquery(select * from content where page_id = get['id'])
$row = fetcharray9$result)
$content = $row['content']
$title = $row['title']

etc.

The content mysql field contains:

$ct = END
pWelcome $username, to the interweb/p
END;

echo $ct


In the heredoc, I can use variables like $username, but not like
$row['username'].

So far this method works just fine, however I want to be able to edit the
content through the website itself. Am I on the right track or is this
awkward? I am implementing a new, login system (mine isn't secure enough)
and I want to implement it correctly.

How should I go about storing content (which may or may not include php)
into a page content field?


[PHP] register_globals and sessions

2009-11-25 Thread Allen McCabe
LPAC - Arts for Youth - Seat OrdersI am getting the following error message,
but ONLY on a page where I am querying multiple tables, and I don't see the
correlation:

*
*
*Warning*: Unknown: Your script possibly relies on a session side-effect
which existed until PHP 4.2.3. Please be advised that the session extension
does not consider global variables as a source of data, unless
register_globals is enabled. You can disable this functionality and this
warning by setting session.bug_compat_42 or session.bug_compat_warn to off,
respectively in *Unknown* on line *0*

I have Googled this extensively, and the solutions other people tried
(turning off the warning) don't work for me; I don't have permission to my
PHP settings (currently working on a free-hosted site).

Does ANYONE know what might be causing this?

On my login page, I use this code snippet to instantiate my SESSION
variables for the session:

// Register $myusername, $mypassword and redirect to default.php?page=211
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;

Again, the error only comes up on the page where I am querying multiple.

If you would like to take a look at this, follow this link and sign in as
username: micky   password: 123456 (
http://lpacmarketing.hostzi.com/afy/orders/)

You will notice on other pages, that error doesn't display, just this one.

Any help would be wonderful, I don't want my users to see this when the
order system is opened for their use.

Thanks!


[PHP] function not returning query

2009-11-23 Thread Allen McCabe
Hi, thanks for reading, I hope you can help:

In my main file for an orders page I have the following code:


if (isset($_GET['filterby']))
 {
  $resultOrders = adminFilterQuery();
  $numberOfOrders = mysql_num_rows($resultOrders);
 }
 else
 {
  $resultOrders = mysql_query(SELECT * FROM afy_order;) or
die(mysql_error(Could not query the database!));
  $numberOfOrders = mysql_num_rows($resultOrders);
 }


adminFilterQuery() is a custom function that is supposed to return a
mysql_query, here are the last few lines of this function:


$query = SELECT * FROM afy_order WHERE school_id = '{$school}' ORDER BY
{$order_by_param};;
$result = mysql_query($query);
return $result;

l am getting this error when I try to filter my query using a form in tandem
with the quey building function:

*Warning*: mysql_num_rows(): supplied argument is not a valid MySQL result
resource

where the line is the one where I use the mysql_num_rows function.

What am I missing here?

Thanks!


Re: [PHP] function not returning query

2009-11-23 Thread Allen McCabe
Okay, suddenly I got it to filter the results, but I still can't figure out
where this part of the query is coming from, at the end of the query string
in the URL, I have this filter.x=0filter.y=0.

No where in my form do I have a field named filter.x or filter.y. I DO
however, have 3 forms (I don't want to mess with AJAX), my set up looks like
this:

Filter by:
User - [username dropdown  v] Order by [database fields  v] Asc/Desc
[Ascend  v] - Go
School - [school dropdown  v] Order by [database fields  v] Asc/Desc
[Ascend  v] - Go
Show - [show dropdown  v] Order by [database fields  v] Asc/Desc [Ascend  v]
- Go

There are actually two order by fields, but this gives you the idea. Each of
the three lines is a separate form, each with a unique name all with a get
method, but all three Go buttons are named filter, I didn't think to try
changing it until now, but is this perhaps where the filter.x and filter.y
are coming from? I have never seen this before in a query.

Oh, now the filter that was working spontaneously gives me the error I have
been getting all along, this is so frustrating.

To those who asked, yes I am connected to the database; I forgot to mention
that the else part of my if statement works, as long as I don't try to
filter my results it works.

Here is an example of the URL that my filter function (via one of the 3
forms) outputs:
http://lpacmarketing.hostzi.com/afy/orders/default.php?filterby=schoolschoolid=36orderby1=order_idasc_desc_order1=Descendorderby2=pmt_recd_dateasc_desc_order2=Descendfilter.x=13filter.y=8filter=Go

On Mon, Nov 23, 2009 at 8:03 PM, Philip Thompson philthath...@gmail.comwrote:

 On Nov 23, 2009, at 6:22 PM, Allen McCabe wrote:

  Hi, thanks for reading, I hope you can help:
 
  In my main file for an orders page I have the following code:
 
 
  if (isset($_GET['filterby']))
  {
   $resultOrders = adminFilterQuery();
   $numberOfOrders = mysql_num_rows($resultOrders);
  }
  else
  {
   $resultOrders = mysql_query(SELECT * FROM afy_order;) or
  die(mysql_error(Could not query the database!));
   $numberOfOrders = mysql_num_rows($resultOrders);
  }

 You reduce this part by one line by putting the following after the else
 statement and removing the other 2:

 $numberOfOrders = mysql_num_rows ($resultOrders);

 Also, these queries don't need a semi-colon (;) to end the query. PHP
 handles this part. Remove them.


  adminFilterQuery() is a custom function that is supposed to return a
  mysql_query, here are the last few lines of this function:
 
 
  $query = SELECT * FROM afy_order WHERE school_id = '{$school}' ORDER BY
  {$order_by_param};;
  $result = mysql_query($query);
  return $result;
 
  l am getting this error when I try to filter my query using a form in
 tandem
  with the quey building function:
 
  *Warning*: mysql_num_rows(): supplied argument is not a valid MySQL
 result
  resource
 
  where the line is the one where I use the mysql_num_rows function.
 
  What am I missing here?
 
  Thanks!

 Do you get this warning with both queries? Make sure that your queries are
 using a valid mysql connection. You may also consider using a database class
 to perform the repetitive tasks so that you really only have to be concerned
 with the queries you're writing...?

 ?php
 class database {
public function query ($sql) {
$result = mysql_query ($sql);
if ($result === false) {
die ('Uh oh!');
}
return $result;
}

public function numRows ($result) {
return mysql_num_rows ($result);
}
 }
 $db = new database();
 $result = $db-query('SELECT * FROM afy_order');
 $numRows = $db-numRows($result);
 ?

 Of course this is just a simple example, but you get the idea. Hope that
 stirs your brain!

 ~Philip


[PHP] [php] [mysql] select and subselect

2009-11-16 Thread Allen McCabe
I have a page on my site where I can optionaly filter by certain fields
(order by filesize or file category), but I am implementing a shopping cart
type of idea where users can submit an order.

As administrators, my coworkers and I need to be able to filter orders by
their contents. For example:

View all orders for Jack and the Beanstalk, where an order may have Jack
and the Beanstalk and other items.

I have an order table that keeps track of the order_id, the date, the
status, etc. I also have an order_lineitem table that is the contents of the
order. This has a one-to-many structure (without foreign keys because it is
mysql).

I was baffled as to how to filter the orders by the item_id that appears in
the order_lineitem table.

I just came up with this, but I'm not sure how the mysql_queries will handle
an array. Do I have to do some extensive regular expression management here
to get this to work, or will it accept an array?

?php

if (isset($_POST['showid']))
   $showid = $_POST['showid'];
   $subSQL = SELECT order_id FROM afy_show_lineitem WHERE show_id =
{$_POST['showid']};;
   $subResult = mysql_query($subSQL);
   $where = WHERE;
   $extQuery = 'order_id = {$subResult}';
  }

$resultOrders = mysql_query(SELECT * FROM afy_order {$where} {$extQuery};)
or die(mysql_error(Could not query the database!));

?


[PHP] Custom function for inserting values into MySQL

2009-11-02 Thread Allen McCabe
Okay friends, I have been wondering about writing a simple function that
will help me with my MySQL inserting. Not because I need to save time and
space, but because I wanted to.

I wrote a function for inserting 10 values (I have not been able to come up
with an idea how to make the number of values I'm inserting variable, so I'm
sticking with ten).

This function takes 22 parameters: #1 is the table name, #2-21 are the row
names and the values, and #22 is the integar string.

The first 21 parameters are self-explanatory, the 22nd is a string of values
that need to be inserted as an integar, basically, not adding single quotes
around the value. Eg. $value2 = 5, not $value2 = '5'.

I am very hesitant to try this one out on my database, I've got tables of
important information and don't want to, I don't know, inadvertantly throw a
wrench into the works, AND I want to open up a dialoug about custom PHP
functions for working with MySQL, for the fun of it!

Here is my 10 value function for inserting data into a MySQL database table.

function insertinto10($table, $field1, $value1, $field2, $value2, $field3,
$value3, $field4, $value4, $field5, $value5, $field6, $value6, $field7,
$value7, $field8, $value8, $field9, $value9, $field10, $value10, $int =
NULL)
{
 if (isset($int))
 {
  $sPattern = '/\s*/m';
  $sReplace = '';
  $int = preg_replace($sPattern, $sReplace, $int);
  $pieces = explode(,, $int); // $pieces[0], $pieces[1] - each equal to
value numbers that are integars
  $length = count($pieces);
  // call custom function to create associative array eg. $newarray[2] = 1,
$newarray[4] = 1, $newarray[5] = 1 . . .
  $integarArray = strtoarray($length, $int);
 }

 $valuesArray = array($value1, $value2, $value3, $value4, $value5, $value6,
$value7, $value8, $value9, $value10);

 foreach ($valuesArray as $key = $value)
 {
  if (isset($integarArray[$key])  $integarArray[$key] == 1)
  {
   // INTEGAR VALUE
   $valuesArray[$key] = mysql_real_escape_string(stripslashes($value));
  }
  else
  {
   // STRING VALUE
   $cleanValue = mysql_real_escape_string(stripslashes($value));
   $valuesArray[$key] = '{$cleanValue}';
  }
 }

 $result = mysql_query(INSERT INTO `{$table}` (`{$field1}`, `{$field2}`,
`{$field3}`, `{$field4}`) VALUES ({$valuesArray[1]}, {$valuesArray[2]},
{$valuesArray[3]}, {$valuesArray[4]}, {$valuesArray[5]}, {$valuesArray[6]},
{$valuesArray[7]}, {$valuesArray[8]}, {$valuesArray[9]},
{$valuesArray[10]}));
 return $result;
}


You may find copying/pasting into your favorite code-editor helps make it
more readable.

Do you see any major hangups or screwups on first glance? And is my fear of
trying this out on my database unfounded? Does this even seem that useful?


[PHP] [php] INSERT and immediately UPDATE

2009-10-28 Thread Allen McCabe
Hey everyone, I have an issue.

I need my (employee) users to be able to insert shows into the our MySQL
database and simultaneously upload an image file (and store the path in the
table).

I have accomplished this with a product-based system (adding products and
uploading images of the product), and accomplished what I needed because the
product name was unique; I used the following statements:

$prodName = $_POST['prodName'];
$prodDesc = $_POST['prodDesc'];
$prodPrice = $_POST['prodPrice'];

$query2  = INSERT INTO product (pID, pName) VALUES (NULL, '$prodName');;
$result2 = mysql_query($query2) or die(mysql_error());

$query  = SELECT pID FROM product WHERE pName = '$prodName';;
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die (mysql_error());

$prodID = $row['pID'];


I had to select the new product to get the product id to use in the new
unique image name.

The problem I am facing now, is that with the shows that my users add will
have multitple show times; this means non-unique titles. In fact, the only
unique identifier is the show id. How can I insert something (leaving the
show_id field NULL so that it is auto-assigned the next ID number), and then
immediately select it?

PHP doesn't seem to be able to immediately select something it has just
inserted, perhaps it needs time to process the database update.

Here is the code I have now (which does not work):

$query2  = INSERT INTO afy_show (show_id, show_title, show_day_w,
show_month, show_day_m, show_year, show_time, show_price, show_description,
show_comments_1, show_seats_reqd) VALUES (NULL, '{$show_title}',
'{$show_day_w}', '{$show_month}', '{$show_day_m}', '{$show_year}',
'{$show_time}', '{$show_price}', '{$show_description}',
'{$show_comments_1}', '{$show_seats_reqd}');;
 $result2 = mysql_query($query2) or die(mysql_error());

 $query3 = SELECT * FROM afy_show WHERE *show_id = '$id'*;;
 $result3 = mysql_query($query3) or die('Record cannot be located!' .
mysql_error());
 $row3 = mysql_fetch_array($result3);
 $show_id = $row3['show_id'];

How do I select the item I just inserted to obtain the ID number??


Re: [PHP] [php] INSERT and immediately UPDATE

2009-10-28 Thread Allen McCabe
You all are great! Thank you so much.



On Wed, Oct 28, 2009 at 12:27 PM, Martin Scotta martinsco...@gmail.comwrote:



 On Wed, Oct 28, 2009 at 4:21 PM, Allen McCabe allenmcc...@gmail.comwrote:

 Hey everyone, I have an issue.

 I need my (employee) users to be able to insert shows into the our MySQL
 database and simultaneously upload an image file (and store the path in
 the
 table).

 I have accomplished this with a product-based system (adding products and
 uploading images of the product), and accomplished what I needed because
 the
 product name was unique; I used the following statements:

 $prodName = $_POST['prodName'];
 $prodDesc = $_POST['prodDesc'];
 $prodPrice = $_POST['prodPrice'];

 $query2  = INSERT INTO product (pID, pName) VALUES (NULL, '$prodName');;
 $result2 = mysql_query($query2) or die(mysql_error());

 $query  = SELECT pID FROM product WHERE pName = '$prodName';;
 $result = mysql_query($query) or die(mysql_error());
 $row = mysql_fetch_array($result) or die (mysql_error());

 $prodID = $row['pID'];


 I had to select the new product to get the product id to use in the new
 unique image name.

 The problem I am facing now, is that with the shows that my users add will
 have multitple show times; this means non-unique titles. In fact, the only
 unique identifier is the show id. How can I insert something (leaving the
 show_id field NULL so that it is auto-assigned the next ID number), and
 then
 immediately select it?

 PHP doesn't seem to be able to immediately select something it has just
 inserted, perhaps it needs time to process the database update.

 Here is the code I have now (which does not work):

 $query2  = INSERT INTO afy_show (show_id, show_title, show_day_w,
 show_month, show_day_m, show_year, show_time, show_price,
 show_description,
 show_comments_1, show_seats_reqd) VALUES (NULL, '{$show_title}',
 '{$show_day_w}', '{$show_month}', '{$show_day_m}', '{$show_year}',
 '{$show_time}', '{$show_price}', '{$show_description}',
 '{$show_comments_1}', '{$show_seats_reqd}');;
  $result2 = mysql_query($query2) or die(mysql_error());

  $query3 = SELECT * FROM afy_show WHERE *show_id = '$id'*;;
  $result3 = mysql_query($query3) or die('Record cannot be located!' .
 mysql_error());
  $row3 = mysql_fetch_array($result3);
  $show_id = $row3['show_id'];

 How do I select the item I just inserted to obtain the ID number??


 mysql_insert_id http://ar.php.net/manual/en/function.mysql-insert-id.php
 mysqli-insert_id http://ar.php.net/manual/en/mysqli.insert-id.php


 --
 Martin Scotta



[PHP] running str_replace, it misbehaves!

2009-08-16 Thread Allen McCabe
Hi friends, I'm trying to get an encrypting program working to possibly use
for password insertion into a db.

I set up a function that runs str_replace on a string (user supplied) two
times. It searches for a single letter or number, and replace it with a
pair. The next str_replace searches that new string for different pairs, and
replaces them with a three-character string (symbol, character, character).
I'm using % as my symbol, so I'm pretty sure this isn't the issue.

It encodes, but the resulting string is way longer than expected!

I set sup a decode function, with the same str_replace values, just with the
replaces flipped. This works to return to me my original value, but I have
to decode about 6 times (after encoding once). Basically, running a string
through the encoding function will decode back to its original value, but I
have to run it through the decode function multiple times to do so.

Here is an example of my code:

[code]

?php
//ENCRYPT FUNCTIONS
function format_string($string,$functions)
{ $funcs = explode(,,$functions);
foreach ($funcs as $func)
{
if (function_exists($func)) $string = $func($string);
}
return $string;
}
function enc_string($string)
{  $search = array(a,b,c,d,e,f,g,h,i,..); //62
values
 $replace = array(j9,k8,q7,v6,...); //62 values
 $string = str_replace($search, $replace, $string);
 $search2 =
array(9k,8q,7v,6w,5x,4y,3z,2j,); // 126
values
 $string = str_replace($search2, $replace2, $string);
 return $string;
}
function scrub($input)
{ $string = format_string($input,strip_tags,trim);
 $string = enc_string($string);
 return $string;
}
if(isset($_POST['input']))
{ $input = $_POST['input'];
 $enc_password = scrub($input);
}
//DECRYPT FUNCTIONS
function format_string2($string2,$functions)
{ $funcs = explode(,,$functions);
foreach ($funcs as $func)
{
if (function_exists($func)) $string2 = $func($string2);
}
return $string2;
}
function dec_string($string2)
{ $search3 = array(%A1,%B2,%C3,); // 126 values
 $replace3 = array(9k,8q,7v,...); //126 values
 $string2 = str_replace($search3, $replace3, $string2);
 $search4 = array(j9,k8,q7,..); //62 values
 $replace4 = array(a,b,c,...); //62 values
 $string2 = str_replace($search4, $replace4, $string2);
 return $string2;
}
function scrub_set2($input2)
{ $string2 = format_string2($input2,strip_tags,trim);
 $string2 = dec_string($string2);
 return $string2;
}
if(isset($_POST['input2']))
{ $input2 = $_POST['input2'];
 $dec_password = scrub_set2($input2);
}
?
body

form (posts to itself) 
input type=text name=input id=input value=?php if(isset($input))
echo $input; ? /
 input type=text name=output id=output value=?php
if(isset($enc_password)) echo $enc_password; ? ?php
if(!isset($enc_password)) echo readonly='readonly'; ? /
input type=submit name=submit value=Encrypt /

[/code]

I have a feeling that php is running the functions through the str_replace
functions multiple times. It doesn't seem to mess with the unique-ness I had
to build into it (in order to preserve the string for decoding), but it
makes me nervous if it runs it through multiple times. Does anyone know why
the encoding step results in such a long string? And why do I have to run
decode on the result so many times to change it back?

Any and all help would be greatly appreciated!


Re: [PHP] session variables - help

2009-08-14 Thread Allen McCabe
Thank you all for your responses.

Mike.

I like the ii option better, mostly because I already have most of that in
place (ie. order posts to process, and process has editable fields and
hidden fields with the remaining complimentary values).
Martin suggested I use the following code for my update script (which is
posted to via the process page):

[code]

foreach($_POST as $key = $value)
if( '0' == $value || '' == $value )
{
/*if*/ session_is_registered( $key ) 
session_unregister( $key );
}

[/code]

I am not following the logic on the above code very well, but is this indeed
a better option? And is not session_*whatever deprecated? The reason I am
using $_SESSION is because it seems that php 6 will use solely this method,
and it currently works with php 5. The other reason I am using it is so that
I can keep the variables stored elsewhere for whenever I need them; I don't
want to have to juggle all the information with POST and hidden inputs
unless it will work seamlessly, and be ready for update at a later date (if
I move to using a database to store show information, or when php 6 is
mainstream).

Keep in mind that once I get the update feature working, I need the process
page to have a final submit button that will insert the order into a
database table AND send a notification email to myself (and an email to the
user). Am I setting myself up for failure with this udate order option? I
ask because the update feature relies on a form, and are not forms limited
to one submit button?

Thanks all for your patience! I will work on this today and write back with
any further questions I can't figure out on my own. And if anyone has any
advice I will be checking my email regularly.

Allen
On Fri, Aug 14, 2009 at 7:52 AM, Ford, Mike m.f...@leedsmet.ac.uk wrote:

  -Original Message-
  From: Allen McCabe [mailto:allenmcc...@gmail.com]
  Sent: 14 August 2009 06:58
 
  Here is some more complete code:
 
  [code = order_process.php]
 
  ?php
  session_start();
  // POST ALL $_POST VALUES, CREATE AS VARIABLES IN SESSION
  foreach($_POST as $k=$v) {
   $_SESSION[$k]=$v;
  }
 
  $thisPage=AFY;  //NAVIGATION PURPOSES
  include(afyshows.php); //CONTAINS ARRAYS FOR SHOW ENTITIES;
  POPULATES
  ORDER FORM
  ?
 
  . . .
 
  /pform name=update action=update_order.php method=post 
   !-- HIDDEN FORM VALUES FOR SESSION PURPOSES --

 Er wait, no! Sessions and hidden form fields are generally alternative
 solutions to the same problem -- you shouldn't be putting the same values
 both in the session and in hidden form fields.  In this case, I'm beginning
 to suspect that the hidden fields are the better solution, but there is a
 certain amount of personal preference in this.

   input type=hidden name=School  id=School value=?php
  $_SESSION['School']; ? /
   input type=hidden name=Grade id=Grade value=?php
  $_SESSION['Grade']; ? /
   input type=hidden name=Address id=Address value=?php
  $_SESSION['Address']; ? /
   input type=hidden name=City id=City value=?php
  $_SESSION['City'];
  ? /
   input type=hidden name=State id=State value=?php
  $_SESSION['State']; ? /
   input type=hidden name=Zip id=Zip size=9 value=?php
  $_SESSION['Zip']; ? /
   input type=hidden name=Contact id=Contact value=?php
  $_SESSION['Contact']; ? /
   input type=hidden name=Phone id=Phone value=?php
  $_SESSION['Phone']; ? /
   input type=hidden name=Fax id=Fax value=?php
  $_SESSION['Fax']; ?
  /
   input type=hidden name=Email id=Email value=?php
  $_SESSION['Email']; ? /
  . . .
 
  ?php
 
  function findTotalCost($b, $c) {
   $total = $b * $c;
   return $total;
  }
 
  function writeResultRow($a, $b, $c, $d, $e, $f) {
   if($a != '') {
echo \ntr\n\t;
echo td'.$b./tdtd.$c./tdtd.$d./td;
echo td.$e./tdtdnbsp;/tdtdinput type='text'
  value='.$a.'
  name='.$a.' id='.$a.' size='2'
  //tdtd=/tdtd\$.$f./td;
echo /tr;
   }
  }
 
  //SETS $Total_show_01 to PRICE * QUANTITY
  //FORMATS TOTAL
  //IF A QUANTITY IS ENTERED, WRITES THE ROW WITH CURRENT VARIABLES
  $Total_show_01 = findTotalCost($shows['show_01']['price'],
  $_SESSION['show_01_qty']);
  $Total_show_01_fmtd = number_format($Total_show_01, 2, '.', '');
  writeResultRow($_SESSION['show_01_qty'], $shows['show_01']['title'],
  $shows['show_01']['date'], $shows['show_01']['time'],
  $shows['show_01']['price'],$Total_show_01_fmtd);
 
  //ABOVE LINES REPEATED FOR ALL 38 ENTITIES (show_01 to show_38)
 
  ?
  . . .
 
  input  name=updates id=updates  type=submit value=Update/
 
  [/code]

 If I'm reading what you want to do correctly, it seems to me there are two
 obvious approaches to this:

 (i) Have a single form which posts back to itself, showing all the show
 information and requested quantities and calculated result fields (such as
 total cost); initially, this will have the calculated fields not displaying
 anything, and these will be (re)populated at each Update.  Using this
 method, all your values are contained solely within the $_POST

Re: [PHP] session variables - help RESOLVED

2009-08-14 Thread Allen McCabe
Thanks everyone for your help, I finally got it working.

For those that were curious, my writeResultRow() function was not naming the
input fields properly, so the SESSION variables could not be updated
properly. I had to add an array item for each show, an id, then call the id
to name the inputs with.

On Fri, Aug 14, 2009 at 11:13 AM, Ben Dunlap bdun...@agentintellect.comwrote:

 Great, hope it helps! -Ben

 On Fri, Aug 14, 2009 at 10:52 AM, Allen McCabeallenmcc...@gmail.com
 wrote:
  This is an EXCELLENT idea.
 



[PHP] session variables - help

2009-08-13 Thread Allen McCabe
I am asking a similar question to one I asked yesterday (which received no
answers) with more information in the hopes someone will be kind enough to
guide me.

I have an order form populated with an array (as opposed to a database
table). The user can enter quantities, and the form posts all the
information to the order_process page where the values they entered are
listed for review.

I decided I wanted to allow them to edit quantities before actually
submitting the form (by which I mean before using the mail() function).

I found that $_SESSION is the way to go.

On the order summary page (order_process.php), I start a session and I get
all the POST information via:

[code]

session_start();

extract($_POST);

[/code]

Instead of echoing the quantity values of each item, I populate an input
field with them within an echo:

[code]

//when this function is called, $a is a the quantity variable $show_01_qty
function writeResultRow($a, $b, $c, $d, $e, $f) {
 if($a != '') {
  echo trinput type='text' value='  . $a .  ' name='  . $a .  ' id='
 . $a .  ' size='2' //td;
  . . .
}
[/code]

Now, in order to update a quantity, the user replaces the quantity in the
input field with the new number, and clicks a submit button which posts to
order_update.php.

I have the following code for order_update.php:

[code]

session_start();
extract($_POST);
foreach ($_POST as $var = $val) {
 if ($val  0) {
  $_SESSION[$var] = $val;
 } else {
  unset($var);

 }
 header(Location: order_process.php);
}

[/code]

This is not working, however, and it just loads order_process.php with no
values for the varaibles, as if I just refreshed the page with no sessions.

Help please!


Re: [PHP] session variables - help

2009-08-13 Thread Allen McCabe
Ben,

First of all, I thank you for your time and help.

My ai with using unset($var) in update_order.php is to set the SESSION
variable for an item to ' ' (empty) so that it would not show up on the
order summary (because my writeResultRow() function will only write a row if
that variable is greater than 0).

I just can't figure out what I'm missing here. Before I received your
response, I made a few changes to my code, which helped streamline the
calculating parts (grabbing values from SESSION instead of POST, and now
when I update order_summary, the values will remain because it pulls them
from the SESSION).

I want to edit the values in the SESSION, so that when update_order.php
redirects to order_process.php, the values are changed, and if applicable,
an item is removed from the html table (if the quantity is less than 1).

Here is some more complete code:

[code = order_process.php]

?php
session_start();
// POST ALL $_POST VALUES, CREATE AS VARIABLES IN SESSION
foreach($_POST as $k=$v) {
 $_SESSION[$k]=$v;
}

$thisPage=AFY;  //NAVIGATION PURPOSES
include(afyshows.php); //CONTAINS ARRAYS FOR SHOW ENTITIES; POPULATES
ORDER FORM
?

. . .

/pform name=update action=update_order.php method=post 
 !-- HIDDEN FORM VALUES FOR SESSION PURPOSES --
 input type=hidden name=School  id=School value=?php
$_SESSION['School']; ? /
 input type=hidden name=Grade id=Grade value=?php
$_SESSION['Grade']; ? /
 input type=hidden name=Address id=Address value=?php
$_SESSION['Address']; ? /
 input type=hidden name=City id=City value=?php $_SESSION['City'];
? /
 input type=hidden name=State id=State value=?php
$_SESSION['State']; ? /
 input type=hidden name=Zip id=Zip size=9 value=?php
$_SESSION['Zip']; ? /
 input type=hidden name=Contact id=Contact value=?php
$_SESSION['Contact']; ? /
 input type=hidden name=Phone id=Phone value=?php
$_SESSION['Phone']; ? /
 input type=hidden name=Fax id=Fax value=?php $_SESSION['Fax']; ?
/
 input type=hidden name=Email id=Email value=?php
$_SESSION['Email']; ? /
. . .

?php

function findTotalCost($b, $c) {
 $total = $b * $c;
 return $total;
}

function writeResultRow($a, $b, $c, $d, $e, $f) {
 if($a != '') {
  echo \ntr\n\t;
  echo td'.$b./tdtd.$c./tdtd.$d./td;
  echo td.$e./tdtdnbsp;/tdtdinput type='text' value='.$a.'
name='.$a.' id='.$a.' size='2' //tdtd=/tdtd\$.$f./td;
  echo /tr;
 }
}

//SETS $Total_show_01 to PRICE * QUANTITY
//FORMATS TOTAL
//IF A QUANTITY IS ENTERED, WRITES THE ROW WITH CURRENT VARIABLES
$Total_show_01 = findTotalCost($shows['show_01']['price'],
$_SESSION['show_01_qty']);
$Total_show_01_fmtd = number_format($Total_show_01, 2, '.', '');
writeResultRow($_SESSION['show_01_qty'], $shows['show_01']['title'],
$shows['show_01']['date'], $shows['show_01']['time'],
$shows['show_01']['price'],$Total_show_01_fmtd);

//ABOVE LINES REPEATED FOR ALL 38 ENTITIES (show_01 to show_38)

?
. . .

input  name=updates id=updates  type=submit value=Update/

[/code]

Now, here is the update_order.php code in entirety:

[code]

?php
session_start();
foreach ($_SESSION as $var = $val) {
 if ($val == 0) {
  unset($_SESSION[$var]);
 } elseif ($val == '') {
  unset($_SESSION[$var]);
 } else {
  $val = $_SESSION[$var];

 }
}
header(Location: order_process.php);

//NOTICE I FIXED THE LOCATION OF THE header() FUNCTION
//BUT IT STILL DOES NOT UPDATE

?

[/code]

If you're still with me, I thank you. I removed all the styling elements
from the html to make it easier for you (and me) to see what it says. I have
invested many hours into this, and have generated many many lines of code,
but I hope what I gave you is sufficient, while not being overwhelming at
this hour.

Thank you very much for your help thus far, anything else would be greatly
appreciated.


On Thu, Aug 13, 2009 at 5:56 PM, Ben Dunlap bdun...@agentintellect.comwrote:



 I have the following code for order_update.php:

 [code]

 session_start();
 extract($_POST);
 foreach ($_POST as $var = $val) {
  if ($val  0) {
  $_SESSION[$var] = $val;
  } else {
  unset($var);

  }
  header(Location: order_process.php);
 }

 [/code]

 This is not working, however, and it just loads order_process.php with no
 values for the varaibles, as if I just refreshed the page with no
 sessions.


 Maybe you left it out but I didn't see any place where you used $_SESSION
 in order_process.php. Also, your redirect in order_update.php appears to be
 inside your foreach loop, which would definitely mess things right up -- but
 maybe that was just a typo in your email?

 Otherwise the logic in order_update.php looks OK, but there are a few side
 notes that jumped out:

 1. I'm not seeing why you used extract($_POST) in order_update.php. Right
 after the extract() call, you iterate through $_POST with a foreach loop, so
 what's the purpose of calling extract()? Is there more code that you left
 out?

 2. Calling extract($_POST) is dangerous. The PHP manual warns against it,
 although without giving much of an explanation:

 

[PHP] Remove function

2009-08-12 Thread Allen McCabe
Hey all.

I am creating an online order form which will submit an order quest to
email, there are no products and no transactions (seat reserving).

Currently, I have a form that is populated with shows and times and prices
from an external php file (each show is an array, embedded in a shows
array).

I have the form working thus so far: a user can enter a quantity for any
show listed (38 shows), and once they hit submit, they are shown a summary,
a table that has each show they chose and all the associated details (pulled
from the external show list file) and tallies their the total number of
seats and the total cost.

I have been thinking about how to add a 'remove' function, or an edit
quantity price. I have it set up so that like this:

[code]

$none = '';

if($show_01_qty != $none) {
 echo  \\ the row with all the details is echoed here

[/code]

I have this set up for all 38 shows.

So all that I need to do, is refresh the page with the quantity set to
$none. Does anyone have any brilliant ideas?

Thanks!


Re: [PHP] Embedding foreach loops

2009-08-10 Thread Allen McCabe
John,

I did this, and got my arrays dumped (on one line). After adding line
returns, here is a snippet:

[code=array dump]

array(38) {
[show_01]= array(5) {
[title]= string(29) Van Cliburn Gold Medal Winner
[date]= string(16) Tues. 10/13/2009
[time]= string(4) 11am
[price]= float(4)
[soldout]= int(0)
}
[show_02]= array(5) {
[title]= string(22) Jack and the Beanstalk
[date]= string(15) Fri. 10/23/2009
[time]= string(4) 11am
[price]= float(4)
[soldout]= int(0)
}

[/code]

and for reference, my original php used to set up arrays

[code=shows.php]

$shows = array();
  $show_01 = array();
  $show_01['title'] = 'Van Cliburn Gold Medal Winner';
  $show_01['date'] = 'Tues. 10/13/2009';
  $show_01['time'] = '11am';
  $show_01['price'] = 4.00;
  $show_01['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE 0 to 1
(without quotations).
 $shows['show_01'] = $show_01;
  $show_02 = array();
  $show_02['title'] = 'Jack and the Beanstalk';
  $show_02['date'] = 'Fri. 10/23/2009';
  $show_02['time'] = '11am';
  $show_02['price'] = 4.00;
  $show_02['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE 0 to 1
(without quotations).
 $shows['show_02'] = $show_02;

[/code]

Does this dump look right?

On Mon, Aug 10, 2009 at 3:04 PM, John Butler
govinda.webdnat...@gmail.comwrote:

  I can't seem to get my foreach loops to work, will PHP parse embedded
 loops?


 yes.

 Is this something I need to have in a database to work?


 no, you can do it with the arrays...  but it may be easier to work with
 over the long run if that data was in a db.

 Anyway right after you finish creating the array and it's embedded arrays,
 in your code, then add this:
 var_dump($shows); //--so you can see what you just created.  If it looks
 right, THEN go on bothering to try and parse it with your (embedded)
 foreach's {

 
 John Butler (Govinda)
 govinda.webdnat...@gmail.com




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




Re: [PHP] Embedding foreach loops

2009-08-10 Thread Allen McCabe
I am using the print function to display my html. I cannot get the line
return ( \n ) character to actually push the html onto the next line, it
just gets displayed instead. Should I be using echo?



On Mon, Aug 10, 2009 at 3:41 PM, John Butler
govinda.webdnat...@gmail.comwrote:


 I did this, and got my arrays dumped (on one line). After adding line
 returns, here is a snippet:



 it looks OK.  Note that you can see (copy/paste) that array which you just
 dumped, much better, if you view the source code of the html page.  OR you
 can use pre to make that format persist thru' to what you see without
 viewing the source., Like so:

echo hr /pre\n;
var_dump($theArray);
echo /pre\n;
echo hr /\n;

 My brain is so full of my own work..  and I am newbie compared to most
 lurking here.. but I am sure we'll figure out your issue if we work on it
 systematically.  OK, your OP just said, ..I can't seem to get my foreach
 loops to work..  , but you never said exactly what is the problem.  Break
 the problem down to the smallest thing that you can find that is not
 behaving as you expect it to, and explain  THAT to me.  We'll do this step
 by step.

 -John


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




[PHP] Trying to create a comment function

2009-08-06 Thread Allen McCabe
I was trying some new things with php today, and was commenting above each
little bit to better see what was working and/or displaying versus what was
not. My comment delineator consisted of the following:

[code]

echo 'brbrfont color=#bbi this is a comment displayed in html
/i/fontbrbr';

[/code]

Then I decided to create a cool function to write that code for me every
time I wanted to write a comment formatted in HTML, so to write a comment
saying this is a comment, I would call a function:

[code]

comment(this is a comment);

[/code]

It was working wonderfully, until I wanted to display test of $newComment
as a comment.

[code]

comment(test of $newComment);

[/code]

This rendered a comment that said test of .

So I added a \ before the $ to make it display properly, but I was wondering
if there was a way that the function could work so that it will display
anything you type within the quotes in comment( ).

Here is my original code for the function comment() :

[code=function comment()]

function comment($commentText = empty comment)
{
echo 'brbrfont color=#bbComment:/fontbr';
 echo 'font color=#bbi'. $newComment .'/i/fontbrbr';
}

[/code]

This would return gray text in 2 lines, Comment: then a line return with the
comment the developer put within the comment() function call in italics.

After noticing that I MUST escape the dollar sign for it to display a
function name in a comment, I tried the following:

[code]

function comment($commentText = empty comment)
{

 $healthy = \$;
 $yummy   = $;
 $newComment = str_replace($healthy, $yummy, $commentText);
 echo 'brbrfont color=#bbComment:/fontbr';
 echo 'font color=#bbi'. $newComment .'/i/fontbrbr';

}

[/code]

This still does not produce the desired results, I still have to escape the
$ when I call the comment() function for the variable name to display.
Again, not a big deal, but I don't want this to beat me.

Anyone have any ideas?


Additionally, when I try to echo $newComment, nothing shows on the screen.
Is this because variables are reset or set to null, or cleared at the end of
a function in which they are used?


Re: [PHP] Trying to create a comment function (RESOLVED)

2009-08-06 Thread Allen McCabe
Asher and Jonathan,

Thank you for your input. Having single quotes around what I wanted to
comment worked to display a variable name.

And Asher, I am constantly scanning the php.net manual, and only after I
could not find what I was looking for did I resort to php-general list. I am
a novice at php, and I don't quite have the familiarity with terms and such
to always find what I'm looking for, or the experience to always know I have
indeed found what I was looking for. I am learning php vis php.net, a PHP
and MySQL for Dummies book, and you fine people on the php-general list.
Additionally, I need things spelled out for me for them to stick, and I
don't have the luxury of asking someone for help who can show in person like
some have had the fortune to have handy when they were learning. I imagine
that there are many who learned as I am, however, seeing as how scripting
and coding is by definition a pioneering endeavour.

Thank you all for the tons of help you have provided, and please bear with
me as I learn. My goal by asking questions of you all is not to get out of
doing any work or research, it's to get myself over the little hangups so I
can proceed with the learning process.

Stay tuned for more 'newbie' questions!

On Thu, Aug 6, 2009 at 1:01 PM, Jonathan Tapicer tapi...@gmail.com wrote:

 
  [code]
 
  comment(test of $newComment);
 
  [/code]
 
  This rendered a comment that said test of .
 
  So I added a \ before the $ to make it display properly, but I was
 wondering
  if there was a way that the function could work so that it will display
  anything you type within the quotes in comment( ).
 

 If you want the string to be rendered as it is without variable
 replacements you can use single quotes, like this:

 comment('test of $newComment');

 That will render exactly this:

 test of $newComment

 Hope that helps you.

 Jonathan



[PHP] navigation include not functioning

2009-08-05 Thread Allen McCabe
I am trying to generate pages by importing content in includes, and using my
navigation include to tell PHP to replace a $thisPage variable which all the
includes use ?php include('phpincludes/' . $thisPage . '.php') ?

The idea behind it (I know tons of people do it, but I'm new to this
concept), is to have a 'layout' page where only a variable changes using
$_GET on an href (index.php?page=services or index.php?page=about) to load
the new 'pages'.

PROBLEM:
All my links are displaying the current page state, and links are not
building around the link text (hrefs are built conditionally with if
$thisPage != services then build the link, otherwise leave it as normal
text). Same thing with the background image behind the link text (to
indicate a page's current position). If the condition is not true, all the
links (except the true current 'page') are supposed reload index.php and
pass a variable to itself to place into $thisPage using
href=index.php?page= (after which I have a variable which stores about
or services within the if statement near the link text.

If this sounds like something you are familiar with (former issues and
whatnot) please let me know what I'm doing wrong. I would be happy to give
you any code you want to look at (index.php or navigation.php, whatever).

Thanks again for your help PHP gurus!


Re: [PHP] navigation include not functioning

2009-08-05 Thread Allen McCabe
Sure.

When I load my site, default.php loads ( displaying:
http://uplinkdesign.hostzi.com/ in the browser as expected). $thisPage is
set to about via:

?php
if (!isset($thisPage)) {
 $thisPage=about;
 } else {
 $thisPage = addslashes($_GET['page']);
 }
?

in the head tags.


I am seeing this:

The first 2 includes work just fine, loading to proper middle section and
proper right-hand-side page content, the navigation include also loads, but
all the of tabs (background images) are the currentpage image, as opposed
to not, as they should be (the the exception of the About Us background
image).

It seems that $thisPage is equal to all four values, so all the if
statements within navigation tell PHP to load the current page image for all
4 links.

Does this help?
On Wed, Aug 5, 2009 at 10:10 AM, Jerry Wilborn jerrywilb...@gmail.comwrote:

 I'm having trouble understanding your description of the problem.  Can you
 tell us what you're seeing and what you expect to see?
 Jerry Wilborn
 jerrywilb...@gmail.com



 On Wed, Aug 5, 2009 at 12:00 PM, Allen McCabe allenmcc...@gmail.comwrote:

 I am trying to generate pages by importing content in includes, and using
 my
 navigation include to tell PHP to replace a $thisPage variable which all
 the
 includes use ?php include('phpincludes/' . $thisPage . '.php') ?

 The idea behind it (I know tons of people do it, but I'm new to this
 concept), is to have a 'layout' page where only a variable changes using
 $_GET on an href (index.php?page=services or index.php?page=about) to load
 the new 'pages'.

 PROBLEM:
 All my links are displaying the current page state, and links are not
 building around the link text (hrefs are built conditionally with if
 $thisPage != services then build the link, otherwise leave it as normal
 text). Same thing with the background image behind the link text (to
 indicate a page's current position). If the condition is not true, all the
 links (except the true current 'page') are supposed reload index.php and
 pass a variable to itself to place into $thisPage using
 href=index.php?page= (after which I have a variable which stores about
 or services within the if statement near the link text.

 If this sounds like something you are familiar with (former issues and
 whatnot) please let me know what I'm doing wrong. I would be happy to give
 you any code you want to look at (index.php or navigation.php, whatever).

 Thanks again for your help PHP gurus!





Re: [PHP] navigation include not functioning

2009-08-05 Thread Allen McCabe
Okay, I see how href=?page=contact would work, and I do indeed have only
one file (which loads includes), but it still is not working. Clicking a
link, be href=?page=contact, href=?page=services, whatever, it still loads
the page with the ?page=whatever attached to the URL, but it is not
subsituting the $page variable within the include snippets, and it just
loads the 'about' versions of all includes (/phpincludes/about_content.php
as opposed to /phpincludes/services_content.php or whichever).

This is really stumping me and try as I might I cannot see why it will not
work. Here is some of my code as it is currently:

On default.php:

[code=default.php]

html
head
?php

$pages = array(
// list of includes:
 'about' , 'services', 'portfolio', 'contact'
);
$page = isset($_GET['page'])  isset($pages[$_GET['page']])  ?
$_GET['page'] : 'about';
// about is default page here

?
title

[/code]

then in the body tags

[code=default.php]

td?php include('phpincludes/' . $page . '_centerbar.php'); ?/td
/tr
 ?php include('phpincludes/nav2.php'); ?
 tr

[/code]
[code=nav2.php]

a href=?page=servicesSERVICES/a

[/code]

It is surprisingly little code and I am starting to wonder if any php
settings on my server are inhibiting this. What do you think?



2009/8/5 ollisso olli...@fromru.com

 On Wed, 05 Aug 2009 22:08:30 +0300, Allen McCabe allenmcc...@gmail.com
 wrote:

 You can do something like that:

 links:
 a href='?page=contact'Contact/a

 This will work if you have only one file, all the time and it is default
 one for current folder. (normally that is index.php, might be default.php in
 your case)

 Second option is to use more harder approach:

 $pos=
 min(strpos($_SERVER['QUERY_STRING'],''),strpos($_SERVER['QUERY_STRING'],'='));
 $act= ($pos!==false) ? substr($_SERVER['QUERY_STRING'], 0,  $pos) :
 $_SERVER['QUERY_STRING'];
 $page   = strtolower($act);

 then you can use links like:
 href='?contact'
 or if you need:
 href='?contact=1' (in case of GET forms)


 Third option is to use mod_rewrite, but this is slightly harder :)

 But then you will be able to use links like:
 www.domain.com/contact/
 (which will work like: index.php?page=contact internally)

 About checking what is included:
 Imagine following scenario:

 $page   = isset($_GET['page']) ? $_GET['page'] : 'about';

 include 'modules/'.$page.'.php';

 Problem here is that you can include ANY file.
 For example:
 ?page=../index
 will work as:
 include 'modules/../index.php';

 Which is crearly not what is intended.

 There is also much more dangerous scenarios of this.

 I hope this explains something :)



 Excellent, your snippet is working nicely. Thank you!

 Unfortunately, when I click a link ( a href=
 http://uplinkdesign.hostzi.com/default.php?page=contact; ),
 deafult.php?contact shows in the browser, but the default (about) content
 is
 loading.

 Also, I don't know what you mean by checking what is included.

 2009/8/5 ollisso olli...@fromru.com

 On Wed, 05 Aug 2009 20:19:00 +0300, Allen McCabe allenmcc...@gmail.com
 wrote:

 Sure.


 When I load my site, default.php loads ( displaying:
 http://uplinkdesign.hostzi.com/ in the browser as expected). $thisPage
 is
 set to about via:

 ?php
 if (!isset($thisPage)) {
  $thisPage=about;
  } else {
  $thisPage = addslashes($_GET['page']);
  }
 ?

 in the head tags.


 I am seeing this:

 The first 2 includes work just fine, loading to proper middle section
 and
 proper right-hand-side page content, the navigation include also loads,
 but
 all the of tabs (background images) are the currentpage image, as
 opposed
 to not, as they should be (the the exception of the About Us background
 image).

 It seems that $thisPage is equal to all four values, so all the if
 statements within navigation tell PHP to load the current page image for
 all
 4 links.

 Does this help?


 Looks like you need something like that:
 $pages  = array(
 // list of modules you have, for example:
  'about' , 'help', etc
 );
 $page   = isset($_GET['page'])  isset($pages[$_GET['page']])  ?
  $_GET['page'] : 'about';
 // about is default page here

 then just:
 include 'modules/'.$page.'.php';

 Always remember that you have to check what is included.
 Best approach(if possible) to have a predefined list of all modules which
 can be included.

 Else, there is some nasty things like:
 ?page=../index.php
 (infinity recurssion)

 ?page=http://otherhost.com/hacker.
 (inclusion of malicious script)
 and so on.




 On Wed, Aug 5, 2009 at 10:10 AM, Jerry Wilborn jerrywilb...@gmail.com

 wrote:

 Look



  I'm having trouble understanding your description of the problem.  Can

 you
 tell us what you're seeing and what you expect to see?
 Jerry Wilborn
 jerrywilb...@gmail.com



 On Wed, Aug 5, 2009 at 12:00 PM, Allen McCabe allenmcc...@gmail.com
 wrote:

 I am trying to generate pages by importing content in includes, and
 using

 my
 navigation include to tell PHP to replace a $thisPage variable which
 all
 the
 includes use

Re: [PHP] navigation include not functioning (RESOLVED)

2009-08-05 Thread Allen McCabe
I just wanted to let know I figured out my last issue (last as in, for now).

In my navigation.php include file, I had if ($page = about) echo href
I changed it to if ($page == about) echo and it suddenly worked! Imagine
that...

Thanks all for you help, you are celebrities in my book now.

On Wed, Aug 5, 2009 at 1:44 PM, Martin Scotta martinsco...@gmail.comwrote:

 You are using a value-filled array as a key-filled. Try this snippet
 and look the results...

 $pages = array('about' , 'services', 'portfolio', 'contact');
 $page = array_key_exists( 'page', $_GET ) ? $_GET[ 'page' ] : 'about';
 /*if*/ false === array_search( $page, $pages, true )  (
$page = 'about'
 );

 # note the sintax used to avoid if-statement
 # this has the same behaviour, but with less performance
 $pages = array('about' , 'services', 'portfolio', 'contact');
 $page = array_key_exists( 'page', $_GET ) ? $_GET[ 'page' ] : 'about';
 if( false === array_search( $page, $pages, true ))
 {
$page = 'about';
  }



 On Wed, Aug 5, 2009 at 5:36 PM, Allen McCabeallenmcc...@gmail.com wrote:
  Okay, I see how href=?page=contact would work, and I do indeed have
 only
  one file (which loads includes), but it still is not working. Clicking a
  link, be href=?page=contact, href=?page=services, whatever, it still
 loads
  the page with the ?page=whatever attached to the URL, but it is not
  subsituting the $page variable within the include snippets, and it just
  loads the 'about' versions of all includes
 (/phpincludes/about_content.php
  as opposed to /phpincludes/services_content.php or whichever).
 
  This is really stumping me and try as I might I cannot see why it will
 not
  work. Here is some of my code as it is currently:
 
  On default.php:
 
  [code=default.php]
 
  html
  head
  ?php
 
  $pages = array(
  // list of includes:
   'about' , 'services', 'portfolio', 'contact'
  );
  $page = isset($_GET['page'])  isset($pages[$_GET['page']])  ?
  $_GET['page'] : 'about';
  // about is default page here
 
  ?
  title
 
  [/code]
 
  then in the body tags
 
  [code=default.php]
 
  td?php include('phpincludes/' . $page . '_centerbar.php'); ?/td
  /tr
   ?php include('phpincludes/nav2.php'); ?
   tr
 
  [/code]
  [code=nav2.php]
 
  a href=?page=servicesSERVICES/a
 
  [/code]
 
  It is surprisingly little code and I am starting to wonder if any php
  settings on my server are inhibiting this. What do you think?
 
 
 
  2009/8/5 ollisso olli...@fromru.com
 
  On Wed, 05 Aug 2009 22:08:30 +0300, Allen McCabe allenmcc...@gmail.com
 
  wrote:
 
  You can do something like that:
 
  links:
  a href='?page=contact'Contact/a
 
  This will work if you have only one file, all the time and it is default
  one for current folder. (normally that is index.php, might be
 default.php in
  your case)
 
  Second option is to use more harder approach:
 
  $pos=
 
 min(strpos($_SERVER['QUERY_STRING'],''),strpos($_SERVER['QUERY_STRING'],'='));
  $act= ($pos!==false) ? substr($_SERVER['QUERY_STRING'], 0,  $pos) :
  $_SERVER['QUERY_STRING'];
  $page   = strtolower($act);
 
  then you can use links like:
  href='?contact'
  or if you need:
  href='?contact=1' (in case of GET forms)
 
 
  Third option is to use mod_rewrite, but this is slightly harder :)
 
  But then you will be able to use links like:
  www.domain.com/contact/
  (which will work like: index.php?page=contact internally)
 
  About checking what is included:
  Imagine following scenario:
 
  $page   = isset($_GET['page']) ? $_GET['page'] : 'about';
 
  include 'modules/'.$page.'.php';
 
  Problem here is that you can include ANY file.
  For example:
  ?page=../index
  will work as:
  include 'modules/../index.php';
 
  Which is crearly not what is intended.
 
  There is also much more dangerous scenarios of this.
 
  I hope this explains something :)
 
 
 
  Excellent, your snippet is working nicely. Thank you!
 
  Unfortunately, when I click a link ( a href=
  http://uplinkdesign.hostzi.com/default.php?page=contact; ),
  deafult.php?contact shows in the browser, but the default (about)
 content
  is
  loading.
 
  Also, I don't know what you mean by checking what is included.
 
  2009/8/5 ollisso olli...@fromru.com
 
  On Wed, 05 Aug 2009 20:19:00 +0300, Allen McCabe 
 allenmcc...@gmail.com
  wrote:
 
  Sure.
 
 
  When I load my site, default.php loads ( displaying:
  http://uplinkdesign.hostzi.com/ in the browser as expected).
 $thisPage
  is
  set to about via:
 
  ?php
  if (!isset($thisPage)) {
   $thisPage=about;
   } else {
   $thisPage = addslashes($_GET['page']);
   }
  ?
 
  in the head tags.
 
 
  I am seeing this:
 
  The first 2 includes work just fine, loading to proper middle section
  and
  proper right-hand-side page content, the navigation include also
 loads,
  but
  all the of tabs (background images) are the currentpage image, as
  opposed
  to not, as they should be (the the exception of the About Us
 background
  image).
 
  It seems

[PHP] issue with mail function

2009-08-04 Thread Allen McCabe
I have recently been working a lot lately with arrays and printing them into
html tables for email (like a user survey for example). I have been seeing
odd things with the table lately, each unique to it's sending php file. I
will get a space in a random spot. In one, I used an array to rename the
Name values of input fields to more readable ones, whatadd becomes What
to Add, only the word 'Add' is spelled 'Ad d'. With my recent mail script
(submitting a customer profile change), I get it in a similar area, a Name
value renamed and I get Emp loyee in the table cell. The adjacent cell is
fine though, reading Needs Handicap Accommodations. I will post some of my
code to show that I haven't misplaced a space:

[code]


   1. ?php
   2.
   3. //CHECKS TO SEE IF FIELDS WERE PROPERLY COMPLETED AND ASSIGNS
   VARIABLES TO INPUTS - OTHERWISE AN ERROR MESSAGE IS PRINTED
   4.
   5. $Employee = $_POST['Employee'];
   6.
   7. $fields2 = array();
   8.
   9. $fields2{Employee} = Employee;
   10. $fields2{IsHandicappedAccommodations} = Needs Handicap
   Accommodations;
   11.
   12. $body = We have received the following
   information:\n\nhtmlbodytable cellspacing='2' cellpadding='2'border=
   '1'tr valign='top';
   13.
   14.
   15. //FOREACH LOOP
   16.
   17. $headerlabel = '0';
   18.
   19. foreach ($fields as $x = $y) {
   20. $headerlabel = $headerlabel +1;
   21. $body .= td{$headerlabel}brimg src='
   http://lpacmarketing.hostzi.com/images/spacer.gif' width='120' height='1'
   /td;
   22. }
   23.
   24.
   25. $body .= /trtr valign='top';
   26.
   27. foreach ($fields2 as $x = $y)
   28. $body .= td{$y}/td;
   29.
   30. $body .= /trtr valign='top';
   31.
   32. foreach ($fields2 as $x = $y)
   33. $body .= td{$_REQUEST[$x]}/td;
   34.
   35. $body .= /trtr valign='top'td colspan='9';
   36.
   37. foreach ($fields as $a = $b) {
   38. $body .= sprintf(%s\n,$b);
   39. }
   40.
   41. $body .= brbr;
   42.
   43. foreach ($fields as $a = $b) {
   44. $body .= sprintf(%s\n,$_POST[$a]);
   45. }
   46.
   47. $body .= /td/tr/table/body/html;
   48.
   49. //END FOREACH LOOPS

[/code]

This is all the code I think is really relevant, but if you think I left
something out I'll be happy to share with you all the code.

This is not a major issue for me, it is just so strange, and if someone
could provide some insight, it would be great.


[PHP] HELP - Parse Error

2009-08-04 Thread Allen McCabe
*Parse error*: syntax error, unexpected $end in *
/home/a9066165/public_html/admin/processccu.php* on line *231*

I did some major code rewriting about halfway through (lines 114-132), and
suddenly I'm getting the above ERROR. I have examined the code line by line,
but I'm still relatively new to this, and I don't even know what to look
for!

Here is the complete code, from beginning ?php tag to closing /html tag:

?php_track_vars?
?php

//CHECKS TO SEE IF FIELDS WERE PROPERLY COMPLETED AND ASSIGNS VARIABLES TO
INPUTS - OTHERWISE AN ERROR MESSAGE IS PRINTED
$Employee = $_POST['Employee'];
if(!empty($_POST['FirstName'])) {
 $FirstName = $_POST['FirstName'];
 } else {
 print p class='error'You have not entered the customer's bFirst
Name/b, please go back and enter it now./p;
 }

if(!empty($_POST['LastName'])) {
 $LastName = $_POST['LastName'];
 } else {
 print p class='error'You have not entered the customer's bLast
Name/b, please go back and enter it now./p;
 }
if(!empty($_POST['EMailAddress'])) {
 $EMailAddress = $_POST['EMailAddress'];
 } else {
 $EMailAddress =  ;
if(!empty($_POST['Address1'])) {
 $Address1 = $_POST['Address1'];
 } else {
 print p class='error'You must supply the customer's bFirst Address
Line/b, please go back and enter it now./p;
 }
if(!empty($_POST['Address2'])) {
 $Address2 = $_POST['Address2'];
 } else {
 $Address2 =  ;
 }
if(!empty($_POST['City'])) {
 $City = $_POST['City'];
 } else {
 print p class='error'You have not entered the customer's bCityb,
please go back and enter it now./p;
 }
if(!empty($_POST['IsHandicappedAccommodations'])) {
 $IsHandicappedAccommodations = YES;
 } else {
 $IsHandicappedAccommodations = NO;
 }
if(!empty($_POST['State'])) {
 $State = $_POST['State'];
 } else {
 print p class='error'You have not entered the customer's bState/b,
please go back and enter it now./p;
 }
if(!empty($_POST['ZIP'])) {
 $ZIP = $_POST['ZIP'];
 } else {
 print p class='error'You have not entered the customer's bZIP
Code/b, please go back and enter it now./p;
 }
if(!empty($_POST['IsSenior'])) {
 $IsSenior = YES;
 } else {
 $IsSenior = NO;
 }
if(!empty($_POST['DaytimeTelephone'])) {
 $DaytimeTelephone = $_POST['DaytimeTelephone'];
 } else {
 print p class='error'You have not entered the customer's bDaytime
Telephone Number/b, please go back and enter it now./p;
 }

$_POST['Category1'] = $Category1;
$_POST['Category2'] = $Category2;
$_POST['Category3'] = $Category3;
$_POST['Category4'] = $Category4;
$_POST['Category5'] = $Category5;
$_POST['Category6'] = $Category6;
$select = Select;

if($Category1 == $select  $Category2 == $select  $Category3 == $select
 $Category4 == $select  $Category5 == $select  $Category6 == $select)
{
 print p class='error'You must choose at least one bCategory/b!/p;
 }

$categoryarray = array($Category1, $Category2, $Category3, $Category4,
$Category5, $Category6);
foreach ($categoryarray as $c) {
 if ($c == $select) {
  $c =  ;
 }
}

//REPLACES NAME VALUES WITH USER-FRIENDLY STRINGS
$fields = array();
$fields{EMailAddress} = Email Address;
$fields{FirstName} = First Name;
$fields{LastName} = Last Name;
$fields{DaytimeTelephone} = Home Phone;
$fields{Address1} = Address Line 1;
$fields{Address2} = Address Line 2;
$fields{City} = City;
$fields{State} = State;
$fields{ZIP} = Postal Code;
$fields2 = array();
$fields2{Employee} = Employee;
$fields2{IsHandicappedAccommodations} = Needs Handicap Accommodations;
$fields2{IsSenior} = Senior Status;
$fields2{Category1} = Email Category 1;
$fields2{Category2} = Email Category 2;
$fields2{Category3} = Email Category 3;
$fields2{Category4} = Email Category 4;
$fields2{Category5} = Email Category 5;
$fields2{Category6} = Email Category 6;
//SETS VARIABLES TO BE USED FOR EMAIL
$to = market...@cityoflancasterca.org;
$subject = Constant Contact Update Form;
$headers = From: $Employee\nMIME-Version: 1.0\nContent-type:
text/html\ncharset: iso-8859-1;
$body = We have received the following
information:\n\nhtml\nbody\ntable cellspacing='2' cellpadding='2'
border='1'\ntr valign='top'\n;
//FOREACH LOOP
$format = %s\t;
$headerlabel = '0';
foreach ($fields as $x = $y) {
 $headerlabel = $headerlabel +1;
 $body .= td{$headerlabel}br\nimg src='
http://lpacmarketing.hostzi.com/images/spacer.gif' width='120'
height='1'/td\n;
}

$body .= /tr\ntr valign='top'\n;
foreach ($fields2 as $x = $y) {
 $body .= td{$y}/td\n;
}
$body .= /tr\ntr valign='top'\n;
foreach ($categoryarray as $d) {
 $body .= td{$d}/td\n;
}

$body .= /tr\ntr valign='top'\ntd colspan='9'pre\n;

foreach ($fields as $a = $b) {
 $body .= sprintf($format, $b);
}
$body .= br;

foreach ($fields as $a = $b) {
 $body .= sprintf($format, $_POST[$a]);
}
$body .= /pre/td\n/tr\n/table\n/body\n/html;
//END FOREACH LOOPS

//SETS VARIABLES TO BE USED FOR THANK-YOU EMAIL

$send = mail($to, $subject, $body, $headers);

//test escape character on URL
if($send) {header(Location: http:/\/
lpacmarketing.hostzi.com/admin/processccu.php);
} else {
 print p class='error'We encountered an error 

Re: [PHP] HELP - Parse Error

2009-08-04 Thread Allen McCabe
Ashley - I am formatting this way, it just didn't translate into gmail : )

Daniel, Martin, and Jim - Thanks very much, my php runs now, however I don't
get the result page anymore. My inbox receives the form (missing cells, but
that's another issue), but the browser doesn't load processccu.php, it says
it cannot display the webpage.

note: I did address the mismatch of the DIV and TABLE (including TR's, TD's)
tags, so I don't think it's my HTML.

On Tue, Aug 4, 2009 at 10:58 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

  On Tue, 2009-08-04 at 10:56 -0700, Jim Lucas wrote:
  Allen McCabe wrote:
   *Parse error*: syntax error, unexpected $end in *
   /home/a9066165/public_html/admin/processccu.php* on line *231*
  
 
  I have learned from a number of similar mistakes that this error message
  /normally/ means that I have a miss-matched number of brackets on a
  foreach, while, or if, etc... statement.
 
  Usually the line number will represent the last line in your script.  In
  this case, they don't seem to match...
 
  Jim
 
   I did some major code rewriting about halfway through (lines 114-132),
 and
   suddenly I'm getting the above ERROR. I have examined the code line by
 line,
   but I'm still relatively new to this, and I don't even know what to
 look
   for!
  
   Here is the complete code, from beginning ?php tag to closing /html
 tag:
  
 
 
 
 Thats why I always prefer to have the brackets line up in the code (I
 forget what the style is called) so that it looks like this:

 function someFunction
 {
if(condition)
{
do something
}
 }

 etc..

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




Re: [PHP] HELP - Parse Error

2009-08-04 Thread Allen McCabe
Well, I got it to display a thank you page instead of what I had. I'm
rolling with the punches. Got to work on why my email table is not building
right. Stay tuned!

On Tue, Aug 4, 2009 at 11:09 AM, Allen McCabe allenmcc...@gmail.com wrote:

 Ashley - I am formatting this way, it just didn't translate into gmail : )

 Daniel, Martin, and Jim - Thanks very much, my php runs now, however I
 don't get the result page anymore. My inbox receives the form (missing
 cells, but that's another issue), but the browser doesn't load
 processccu.php, it says it cannot display the webpage.

 note: I did address the mismatch of the DIV and TABLE (including TR's,
 TD's) tags, so I don't think it's my HTML.

   On Tue, Aug 4, 2009 at 10:58 AM, Ashley Sheridan 
 a...@ashleysheridan.co.uk wrote:

  On Tue, 2009-08-04 at 10:56 -0700, Jim Lucas wrote:
  Allen McCabe wrote:
   *Parse error*: syntax error, unexpected $end in *
   /home/a9066165/public_html/admin/processccu.php* on line *231*
  
 
  I have learned from a number of similar mistakes that this error message
  /normally/ means that I have a miss-matched number of brackets on a
  foreach, while, or if, etc... statement.
 
  Usually the line number will represent the last line in your script.  In
  this case, they don't seem to match...
 
  Jim
 
   I did some major code rewriting about halfway through (lines 114-132),
 and
   suddenly I'm getting the above ERROR. I have examined the code line by
 line,
   but I'm still relatively new to this, and I don't even know what to
 look
   for!
  
   Here is the complete code, from beginning ?php tag to closing /html
 tag:
  
 
 
 
 Thats why I always prefer to have the brackets line up in the code (I
 forget what the style is called) so that it looks like this:

 function someFunction
 {
if(condition)
{
do something
}
 }

 etc..

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk





Re: [PHP] HELP - Parse Error

2009-08-04 Thread Allen McCabe
I created a webpage with the code listed, and a screen shot of the email I
am currently receiving (with nonsense entered into my inputs)

URL:
http://lpacmarketing.hostzi.com/admin/help.html

Anyone that can provide help will be rewarded in their next life. That's a
promise.

Thanks!

On Tue, Aug 4, 2009 at 10:58 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

  On Tue, 2009-08-04 at 10:56 -0700, Jim Lucas wrote:
  Allen McCabe wrote:
   *Parse error*: syntax error, unexpected $end in *
   /home/a9066165/public_html/admin/processccu.php* on line *231*
  
 
  I have learned from a number of similar mistakes that this error message
  /normally/ means that I have a miss-matched number of brackets on a
  foreach, while, or if, etc... statement.
 
  Usually the line number will represent the last line in your script.  In
  this case, they don't seem to match...
 
  Jim
 
   I did some major code rewriting about halfway through (lines 114-132),
 and
   suddenly I'm getting the above ERROR. I have examined the code line by
 line,
   but I'm still relatively new to this, and I don't even know what to
 look
   for!
  
   Here is the complete code, from beginning ?php tag to closing /html
 tag:
  
 
 
 
 Thats why I always prefer to have the brackets line up in the code (I
 forget what the style is called) so that it looks like this:

 function someFunction
 {
if(condition)
{
do something
}
 }

 etc..

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




[PHP] isset not functioning

2009-08-03 Thread Allen McCabe
I created a simple survey for my work website, most of the PHP is on my
process.php document, which is referenced by a form on a seperate page
containing the form with the method of post.

On my process.php page, the script obtains the field data using the
$_REQUEST[] function.

I have a small if statement to check to see if they filled out the
'firstname' field, and if they did not, to replace $name with Sir or
Madam. Unfortunately, $name always equals Sir or Madam, wether a value
for firstname was entered or not.

All the of the other instances of using $_REQUEST[] functions just fine, but
don't make use of if or isset. Here is the code snippet:

if(isset($_REQUEST['firstname'])  !empty($RESULT['firstname'])) {
 $name = $_REQUEST['firstname'];
 } else {
 $name = 'Sir or Madam';
}

I also tried adding an underscore to $RESULT (I got the code for this from a
php.net comment on the manual), to make it $_RESULT, but this doesn't seem
to be a pre-set function, and it still does not make it work. I am guessing
the user neglected to define $RESULT in his snippet, or I overlooked it.

Can anyone see any problems with the code?


Re: [PHP] isset not functioning -RESOLVED

2009-08-03 Thread Allen McCabe
Thanks!

On Mon, Aug 3, 2009 at 10:13 AM, Andrew Ballard aball...@gmail.com wrote:

  On Mon, Aug 3, 2009 at 1:08 PM, Allen McCabeallenmcc...@gmail.com
 wrote:
  I created a simple survey for my work website, most of the PHP is on my
  process.php document, which is referenced by a form on a seperate page
  containing the form with the method of post.
 
  On my process.php page, the script obtains the field data using the
  $_REQUEST[] function.
 
  I have a small if statement to check to see if they filled out the
  'firstname' field, and if they did not, to replace $name with Sir or
  Madam. Unfortunately, $name always equals Sir or Madam, wether a value
  for firstname was entered or not.
 
  All the of the other instances of using $_REQUEST[] functions just fine,
 but
  don't make use of if or isset. Here is the code snippet:
 
  if(isset($_REQUEST['firstname'])  !empty($RESULT['firstname'])) {
   $name = $_REQUEST['firstname'];
   } else {
   $name = 'Sir or Madam';
  }
 
  I also tried adding an underscore to $RESULT (I got the code for this
 from a
  php.net comment on the manual), to make it $_RESULT, but this doesn't
 seem
  to be a pre-set function, and it still does not make it work. I am
 guessing
  the user neglected to define $RESULT in his snippet, or I overlooked it.
 
  Can anyone see any problems with the code?
 

 You are switching from $_REQUEST to $RESULT. Trying to use $_RESULT
 won't make it any better.

 Andrew



[PHP] Creating/printing array issues

2009-07-28 Thread Allen McCabe
I found a php script to find all file types with a file-name formula and put
them into an array. I then wanted to echo this array (possibly with links to
the files).

I want my default page to look for and list all php files with
survey_*.php, the asterisk being any number, so the results should be:
survey_01.php, survey_02.php, etc.

Here is my code:

?php
/**
* Recursive version of glob
*
* @return array containing all pattern-matched files.
*
* @param string $sDir  Directory to start with.
* @param string $sPattern  Pattern to glob for.
* @param int $nFlags   Flags sent to glob.
*/
function rglob($sDir, $sPattern, $nFlags = NULL)
{
 $sDir = escapeshellcmd($sDir);
 // Get the list of all matching files currently in the
 // directory.
 $aFiles = glob($sDir/$sPattern, $nFlags);
 // Then get a list of all directories in this directory, and
 // run ourselves on the resulting array.  This is the
 // recursion step, which will not execute if there are no
 // directories.
 foreach (glob($sDir/*, GLOB_ONLYDIR) as $sSubDir)
 {
  $aSubFiles = rglob($sSubDir, $sPattern, $nFlags);
  $aFiles = array_merge($aFiles, $aSubFiles);
 }
 // The array we return contains the files we found, and the
 // files all of our children found.
 return $aFiles;
}
$aryPhotos = 
rglob(./surveys,\\{survey_*.php},GLOB_BRACEfile://%7bsurvey_*.php%7d%22,glob_brace/
);
$aryExt = array(php);
$propid = $_REQUEST['mlsid']; // I assume the id will be in the querystring
// get the proper match pattern according to our Extension criteria
foreach ($aryExt as $e) {
 $aryPattern[] = $propid._*.$e;
}
$pattern = join(,, $aryPattern); // comma separated list
// Get the filenames
$aryPhotos = 
rglob(./surveys,\\{$pattern},GLOB_BRACEfile://%7b$pattern%7d%22,glob_brace/);

//print out our array
print_r($aryPhotos);


?


Also, it would be nice to have an if/else statement to say there are no
surveys (survey_*.php files) available if there are none in the /surveys
directory.

Any and all help would be greatly appreciated!

-Allen McCabe


[PHP] Re: Creating/printing array issues

2009-07-28 Thread Allen McCabe
By the way, I was getting a PHP error with an unexpected ) on line 47
($aryPhotos), so I added the two \\ before {survey*_.php and now the page
won't load, won't even display a PHP error.



On Tue, Jul 28, 2009 at 11:06 AM, Allen McCabe allenmcc...@gmail.comwrote:

 I found a php script to find all file types with a file-name formula and
 put them into an array. I then wanted to echo this array (possibly with
 links to the files).

 I want my default page to look for and list all php files with
 survey_*.php, the asterisk being any number, so the results should be:
 survey_01.php, survey_02.php, etc.

 Here is my code:

 ?php
 /**
 * Recursive version of glob
 *
 * @return array containing all pattern-matched files.
 *
 * @param string $sDir  Directory to start with.
 * @param string $sPattern  Pattern to glob for.
 * @param int $nFlags   Flags sent to glob.
 */
 function rglob($sDir, $sPattern, $nFlags = NULL)
 {
  $sDir = escapeshellcmd($sDir);
  // Get the list of all matching files currently in the
  // directory.
  $aFiles = glob($sDir/$sPattern, $nFlags);
  // Then get a list of all directories in this directory, and
  // run ourselves on the resulting array.  This is the
  // recursion step, which will not execute if there are no
  // directories.
  foreach (glob($sDir/*, GLOB_ONLYDIR) as $sSubDir)
  {
   $aSubFiles = rglob($sSubDir, $sPattern, $nFlags);
   $aFiles = array_merge($aFiles, $aSubFiles);
  }
  // The array we return contains the files we found, and the
  // files all of our children found.
  return $aFiles;
 }
 $aryPhotos = rglob(./surveys,\\{survey_*.php},GLOB_BRACE);
 $aryExt = array(php);
 $propid = $_REQUEST['mlsid']; // I assume the id will be in the querystring

 // get the proper match pattern according to our Extension criteria
 foreach ($aryExt as $e) {
  $aryPattern[] = $propid._*.$e;
 }
 $pattern = join(,, $aryPattern); // comma separated list
 // Get the filenames
 $aryPhotos = rglob(./surveys,\\{$pattern},GLOB_BRACE);
 //print out our array
 print_r($aryPhotos);


 ?


 Also, it would be nice to have an if/else statement to say there are no
 surveys (survey_*.php files) available if there are none in the /surveys
 directory.

 Any and all help would be greatly appreciated!

 -Allen McCabe