[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:


);
$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


[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 wrote:

> 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:
>
>  /**
> * 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
>


[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  wrote:

>  On Mon, Aug 3, 2009 at 1:08 PM, Allen McCabe
> 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] 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. ";
   13.
   14.
   15. //FOREACH LOOP
   16.
   17. $headerlabel = '0';
   18.
   19. foreach ($fields as $x => $y) {
   20. $headerlabel = $headerlabel +1;
   21. $body .= "{$headerlabel}";
   22. }
   23.
   24.
   25. $body .= "";
   26.
   27. foreach ($fields2 as $x => $y)
   28. $body .= "{$y}";
   29.
   30. $body .= "";
   31.
   32. foreach ($fields2 as $x => $y)
   33. $body .= "{$_REQUEST[$x]}";
   34.
   35. $body .= "";
   36.
   37. foreach ($fields as $a => $b) {
   38. $body .= sprintf("%s\n",$b);
   39. }
   40.
   41. $body .= "";
   42.
   43. foreach ($fields as $a => $b) {
   44. $body .= sprintf("%s\n",$_POST[$a]);
   45. }
   46.
   47. $body .= "";
   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  tag:


You have not entered the customer's First
Name, please go back and enter it now.";
 }

if(!empty($_POST['LastName'])) {
 $LastName = $_POST['LastName'];
 } else {
 print "You have not entered the customer's Last
Name, please go back and enter it now.";
 }
if(!empty($_POST['EMailAddress'])) {
 $EMailAddress = $_POST['EMailAddress'];
 } else {
 $EMailAddress = " ";
if(!empty($_POST['Address1'])) {
 $Address1 = $_POST['Address1'];
 } else {
 print "You must supply the customer's First Address
Line, please go back and enter it now.";
 }
if(!empty($_POST['Address2'])) {
 $Address2 = $_POST['Address2'];
 } else {
 $Address2 = " ";
 }
if(!empty($_POST['City'])) {
 $City = $_POST['City'];
 } else {
 print "You have not entered the customer's City,
please go back and enter it now.";
 }
if(!empty($_POST['IsHandicappedAccommodations'])) {
 $IsHandicappedAccommodations = "YES";
 } else {
 $IsHandicappedAccommodations = "NO";
 }
if(!empty($_POST['State'])) {
 $State = $_POST['State'];
 } else {
 print "You have not entered the customer's State,
please go back and enter it now.";
 }
if(!empty($_POST['ZIP'])) {
 $ZIP = $_POST['ZIP'];
 } else {
 print "You have not entered the customer's ZIP
Code, please go back and enter it now.";
 }
if(!empty($_POST['IsSenior'])) {
 $IsSenior = "YES";
 } else {
 $IsSenior = "NO";
 }
if(!empty($_POST['DaytimeTelephone'])) {
 $DaytimeTelephone = $_POST['DaytimeTelephone'];
 } else {
 print "You have not entered the customer's Daytime
Telephone Number, please go back and enter it now.";
 }

$_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 "You must choose at least one Category!";
 }

$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\n\n\n\n\n";
//FOREACH LOOP
$format = "%s\t";
$headerlabel = '0';
foreach ($fields as $x => $y) {
 $headerlabel = $headerlabel +1;
 $body .= "{$headerlabel}\n\n";
}

$body .= "\n\n";
foreach ($fields2 as $x => $y) {
 $body .= "{$y}\n";
}
$body .= "\n\n";
foreach ($categoryarray as $d) {
 $body .= "{$d}\n";
}

$body .= "\n\n\n";

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

foreach ($fields as $a => $b) {
 $body .= sprintf($format, $_POST[$a]);
}
$body .= "\n\n\n\n";
//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 "We encountered an error submitting your survey!
Please notify 
market...@cityoflancasterca.org.
>";
 }
?>

  
 

 





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
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 
> 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  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 
>> 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
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 
> 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] 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 

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:



in the  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 wrote:

> 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 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 
>>
>> 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]






[/code]

then in the body tags

[code=default.php]



 
 

[/code]
[code=nav2.php]

SERVICES

[/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 

> On Wed, 05 Aug 2009 22:08:30 +0300, Allen McCabe 
> wrote:
>
> You can do something like that:
>
> links:
> Contact
>
> 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 ( 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 
>>
>> On Wed, 05 Aug 2009 20:19:00 +0300, Allen McCabe 
>>> 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:
>>>>
>>>> >>> if (!isset($thisPage)) {
>>>>  $thisPage="about";
>>>>  } else {
>>>>  $thisPage = addslashes($_GET['page']);
>>>>  }
>>>> ?>
>>>>
>>>> in the  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:
&

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 wrote:

> 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 McCabe 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]
> >
> > 
> > 
> >  >
> > $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
> >
> > ?>
> > 
> >
> > [/code]
> >
> > then in the body tags
> >
> > [code=default.php]
> >
> > 
> > 
> >  
> >  
> >
> > [/code]
> > [code=nav2.php]
> >
> > SERVICES
> >
> > [/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 
> >
> >> On Wed, 05 Aug 2009 22:08:30 +0300, Allen McCabe  >
> >> wrote:
> >>
> >> You can do something like that:
> >>
> >> links:
> >> Contact
> >>
> >> 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';
> >>
> >

[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 ' this is a comment displayed in html
';

[/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 'Comment:';
 echo ''. $newComment .'';
}

[/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 'Comment:';
 echo ''. $newComment .'';

}

[/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  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] Embedded foreach loops

2009-08-10 Thread Allen McCabe
I am creating an order form for tickets for a list of performances at a
performing arts center.

Currently, the form is on paper, and is set up as follows:
-Nutcracker - Tues 10/13 - 11am - $4.00


[PHP] Embedding foreach loops

2009-08-10 Thread Allen McCabe
Gmail automatically sent my last email, apologies.

I am creating an order form for tickets for a list of performances at a
performing arts center.

Currently, the form is on paper, and is set up as follows:
-Title - date  - time - price - soldout - quantity - total($)
-Nutcracker - Tues 10/13 -  9am - $4.00 - yes/no  -  - __
-Nutcracker - Tues 10/13 - 11am - $4.00 - yes/no  -  - __
-Mayhem P.. - Thur 01/21 -  9am - $4.00 - yes/no  -  - __
-Mayhem P.. - Thur 01/21 - 11am - $4.00 - yes/no  -  - __
-Max and... - Tues 04/21 -  9am - $4.00 - yes/no  -  - __

A given show may have between 1 and 4 performances, and I figured the best
way to approach this was to consider each show time for each show as an
entity. There are 19 unique titles, but given different showtimes, it
becomes 38 'shows'.

I have the shows in an array ($shows), and the details for each show in its
own array (eg. $show_01) embedded into the show array.

I need to generate a row for each show (so 38 rows), and assign quantity and
total input fields a unique name and id.

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

Here is an example of my embedded arrays:

[code=shows.php]

$shows = array();

 $shows['show_01'] = $show_01;
  $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_02'] = $show_02;
  $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).

[/code]

And here are the foreach loops I'm trying to build the rows with:

[code=order.php]

 $value) {
 foreach ($value as $key2 => $value2) {
  print '  '. $value2 .'';
 }
 print '';
 print '  ';
 print '  $';
 print '';
 print '  yes/no';
 print '';
}
?>

[/code]

In case you were wondering why I embedded the foreach statement, I need each
array (eg. $show_22) to display in a row, and I need PHP to build as many
rows are there are shows.

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

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
wrote:

>  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
wrote:

>
> 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  to make that format persist thru' to what you see without
> viewing the source., Like so:
>
>echo "\n";
>var_dump($theArray);
>echo "\n";
>echo "\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] Is select_db necessary?

2009-08-11 Thread Allen McCabe
I have seen different scripts for working with SQL, and most follow the same
method with on difference.

Variables are defined (host, password, etc.)
mysql_connect command

//then, the difference

mysql_select_db command

//back to common

$sql = "SELECT ... "
$result = mysql_query($ql)

Is the database selection necessary, or is that implied with a SELECT or
other SQL command?


[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!


[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 "";
  . . .
}
[/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]

$v) {
 $_SESSION[$k]=$v;
}

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

. . .


 
 
 
 
 
 
 
 
 
 
 
. . .

\n\t";
  echo "".$b."".$c."".$d."";
  echo "".$e." =\$".$f."";
  echo "";
 }
}

//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)

?>
. . .



[/code]

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

[code]

 $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 wrote:

>
>
>> 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:
>
> http://us2.php.net/manual/en/function.extract.php
>
> Apart from making it difficult to filter the input you're expecting to see,
> "extract($_POST)" also allows a malicious end-user to define any variable of
> his choosing and to overwrite any variables that you may have defined in the
> script before the extract() call.
>
> I like to use filter_input() to read the values of POST variables.
>
> By much the same token, you'll want to escape $a, etc., in your
> writeResultRow() function, with something like htmlentities().
>
> 3. Why the "unset($var)" in order_update.php? $var already gets reset each
> time foreach iterates. So, calling unset() on it at the end of the loop
> doesn't really do much. I'm wondering what you were aiming at there.
>
> Thanks,
>
> Ben
>
>


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  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]
> >
> >  > 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
> > ?>
> >
> > . . .
> >
> > 
> >  
>
> 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.
>
> >  
> >  
> >  
> >  
> >  
> >  
> >  
> >  
> >   > />
> >  
> > . . .
> >
> >  >
> > function findTotalCost($b, $c) {
> >  $total = $b * $c;
> >  return $total;
> > }
> >
> > function writeResultRow($a, $b, $c, $d, $e, $f) {
> >  if($a != '') {
> >   echo "\n\n\t";
> >   echo "".$b."".$c."".$d."";
> >   echo "".$e."  > value='".$a."'
> > name='".$a."' id='".$a."' size='2'
> > />=\$".$f."";
> >   echo "";
> >  }
> > }
> >
> > //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)
> >
> > ?>
> > . . .
> >
> > 
> >
> > [/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. 

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 wrote:

> Great, hope it helps! -Ben
>
> On Fri, Aug 14, 2009 at 10:52 AM, Allen McCabe
> wrote:
> > This is an EXCELLENT idea.
> >
>


[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]






  />


[/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!


[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 wrote:

>
>
> On Wed, Oct 28, 2009 at 4:21 PM, Allen McCabe wrote:
>
>> 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] 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] & [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] 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=0&filter.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=school&schoolid=36&orderby1=order_id&asc_desc_order1=Descend&orderby2=pmt_recd_date&asc_desc_order2=Descend&filter.x=13&filter.y=8&filter=Go

On Mon, Nov 23, 2009 at 8:03 PM, Philip Thompson wrote:

> 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...?
>
>  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] 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] 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:



The page definition file looks like this:

logout()){
  echo 'You have been logged
out';
 }
}

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

// Attempted login url - use for redirect after login.
$redirect = 
"http://mwclans.com/{$_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/");
die(); }
}
?>

Here is the Sentry class:

userdata))
  {
   unset($this->userdata);
   $session_name = session_name();
   return true;
  }
  else
  {
   $message = "Call to non-object by
function: logout()";
  }

 }
 
//==
 // 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){
// Login OK, store session details
// Log in
$_SESSION["username"] = $username;
$_SESSION["password"] = $this->userdata['password'];
$_SESSION["user_id"] = $this->userdata['user_id'];
$_SESSION["role_id"] = $this->userdata['role_id'];

if ($goodRedirect) {
 header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
}
return true;
   }else{
// Login BAD
unset($this->userdata);
if ($badRedirect) {
 header("Location: ".$badRedirect) ;
}
return false;
   }
  }
 }
}
?>

And here is the login page:

query($loginsettingquery);
$loginsettinginfo = $connector->fetchArray($loginsettingresult);
$currentpage = 
"http://mwclans.com/{$_SERVER['REQUEST_URI'
]}";
if (isset($_SESSION['username']) && isset($_SESSION['password'])) // display
other info, else display login form
{
 // logged-in user tools
}
else
{
if ($loginsettinginfo['value'] == 1 || $directory == "cmsadmin")
{
 $signinform = <<
 
  Login
 
 
  Username:
  
  
  
  
 
 
  Password:
  
  
 
 
  
 

END;
}
else
{
 // login disabled message
}
}
?>


[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 = <

[PHP] CMS - Deployable Zip and MySQL idea

2009-12-05 Thread Allen McCabe
For the fun (and experience) of it, I am building a PHP content management
system compatible with MySQL. I want to be able to drop a ZIP file into
someone's root folder, extract, and load the index file in the admin folder
is deploys.

I had that part worked out, redirect the user to a "Add MySQL Connection"
form if no MySQL database connection is available. I had pretty much all the
code in place when I realized,how am I going to add database connection
information through a webpage that isn't already manually connected?

Usually the login information for MySQL is hard coded into the PHP scripts.
How can I connect to a database without hard coding it?

Take a moment to think about how you would resolve this. I'm sure what I
came up with is probably not so elegant as what most of you will come up
with, but this is what I did.


I set up some logic at the beginning of  admin/index.php to check for a
specific directory in the root folder (called "_spin"), if it returns false
(as it is supposed to the first time admin/index.php is run), it creates the
folder with 0750 permissions (to make it private). Next it creates a text
file called KEY.txt in that new directory with the string "temp", and then
redirects to the database add form (any attempt to directly call the .txt
file results in a 404).

If the file KEY.txt is found in the directory _spin, it reads it to get the
database connect credentials. At the database add form, KEY.txt is opened
and "temp" is replaced with the POST(ed) data (host, username, password,
database name). After KEY.txt is saved, these values are also added to a
site_settings tables (which is created at the same time).

Now in the future, the database connection profile can be deleted but still
maintain connection, or conversely, the KEY.txt file can be unlink(ed) to
effectively start over (at which point the database tables can optionally be
dropped simultaneously).

And for error handling, the initial logic checks the contents of the text
file so if find anything besides "temp" as the first item (contents exploded
as CSV variables with spaces as the seperator), so your server cannot be
named exactly "temp", it uses the CSV variables as the mysql_connect()
parameters ("localhost username password dbname" is put into $conn[0],
$conn[1], $conn[2], and $conn[3]).

So are there any obvious security flaws with this?

Is this a method that others use or did I come up with something unique?


[PHP] includes linking to other files, help with relatives

2009-12-06 Thread Allen McCabe
I am creating a database connection path that check for a session variable
to get the username, password, dbname, etc., but if the session has not been
set yet, I need my script to get those values from another file
(KEY.txt) where they are saved. I want to access this class from two
directories, and this text file (KEY.txt) is in a directory above both. Like
this:

root: folder1 - folder2

folder1: KEY.txt

folder2: index.php - database.php - folder3

folder3: index.php

I need to use database.php in both index files, but database.php references
KEY.txt. So my question is, do I have to check which directory the calling
script is in (ie. which index.php file is using database.php) and add the
according up directory references, or do I need to use some kind of
$_SERVER[DOCUMENT_ROOT]
thing?

Any help would be appreciated!


[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:



, ,  etc.



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.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.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] 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] 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 = "Orders successfully Purged!(Order #'s deleted: {$expired_order_ids_str})";
  }
  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] 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 = ''. $string .'';
  $this->q[] = $message;
 }

 public function printQ()
 {
  if (isset($q))
  {
   echo '';
   foreach($this->q as $msg)
   {
echo $msg ."\n";
   }
   echo '';
  }

  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!


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:

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?

?>
...
...

printQ()  ?>

On Mon, Dec 14, 2009 at 6:07 PM, Nirmalya Lahiri
wrote:

> --- On Tue, 12/15/09, Allen McCabe  wrote:
>
> > From: Allen McCabe 
> > Subject: [PHP] Class not functioning
> > To: "phpList" 
> > 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 = ''.
> > $string .'';
> >   $this->q[] = $message;
> >  }
> >
> >  public function printQ()
> >  {
> >   if (isset($q))
> >   {
> >echo ' > class="notification">';
> >foreach($this->q as $msg)
> >{
> > echo $msg ."\n";
> >}
> >echo '';
> >   }
> >
> >   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[] = '
>> > > 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 = ''.
>> > > $string .'';
>> > >   $this->q[] = $message;
>> > >  }
>> > >
>> > >  public function printQ()
>> > >  {
>> > >   if (isset($q))
>> > >   {
>> > >echo '> > > class="notification">';
>> > >foreach($this->q as $msg)
>> > >{
>> > > echo $msg ."\n";
>> > >}
>> > >echo '';
>> > >   }
>> > >
>> > >   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] 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
wrote:

>   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[] = ' ... '; 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 
>
> 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[] = '
>>>> > > 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 = ''.
>>>> > > $string .'';
>>>> > >   $this->q[] = $message;
>>>> > >  }
>>>> > >
>>>> > >  public function printQ()
>>>> > >  {
>>>> > >   if (isset($q))
>>>> > >   {
>>>> > >echo '>>> > > class="notification">';
>>>> > >foreach($this->q as $msg)
>>>> > >{
>>>> > > echo $msg ."\n";
>>>> > >}
>>>> > >echo '';
>>>> > >   }
>>>> > >
>>>> > >   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

Re: [PHP] OOP: __construct() and "extend"

2009-12-22 Thread Allen McCabe
Extended classes may have their own constructors which are implicitly
called, and as Jonathan mentioned, the constructor of any ancestors (ie. the
parent) must explicitly be called.

If the child (extended) class does NOT have it's own constructor method
defined, the parent's constructor is called.

Manual: http://php.net/manual/en/language.oop5.decon.php


On Tue, Dec 22, 2009 at 2:45 PM, APseudoUtopia wrote:

> Hey list,
>
> I'm writing my own class which extends upon the Memcached class
> (php.net/memcached).
>
> I'm a bit confused as to how the constructor works when extending a class.
>
> class caching extends Memcached {
> function __construct() {
> echo "Caching Class Construct!";
> }
> }
>
> For something like the above code, is the Memcached constructor
> called? Or do I have to explicitly call it via parent::__construct()
> within the caching class?
>
> Thanks.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


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:



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:



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  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:
>>
>>
>> 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] 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!


[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.

' .
"\n";
foreach ($fields as $field)
{
 // ROW BEGIN
 echo "\t" . '' . "\n";
 // NAME OF FIELD
 echo "\t\t" . '`' . $field['field'] . '`: ' . "\n";
 // FIELD DATA TYPE
 echo "\t\t" . '' . $field['type'] . '' . "\n";
 // VALUE INPUT
 echo "\t\t" . '';
 $input_type = printByType($field['type'], 'INPUT_TYPE');
 echo '';
 echo '' . "\n";
 echo "\t" . '' . "\n";
}
echo '';

?>

The function:

 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] 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  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] "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:

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] = '

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

Link.class.php:



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

Database.class.php:



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  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:
>>
>> >$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] = '>foreach ($properties as $prop)
>>{
>>$link[$i] .= $prop;
>>}
>>$link[$i] .= '>';
>>$row['text'];
>>$link[$i] .= '';
>>
>>$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:
>>
>> >
>> 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:
>>
>> >
>> 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] 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:











Does this make sense?


Anyone else have any questions/comments/critiques?


On Wed, Jan 20, 2010 at 7:29 PM, Hendry  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:





http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
http://www.w3.org/1999/xhtml";
xmlns:v="urn:schemas-microsoft-com:vml" >

 - 
















query('SELECT * FROM `links` WHERE `category` =
\'primary_navigation\'');

while ($listitem = $db->fetch_array($result))
{
echo "\t" . '' . $listitem['text'] . '' . "\n";
}
?>

 







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
?>





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" . '' . "\n";
}

$i++;
}
}
}
?>
The 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
positioning.





query('SELECT * FROM `components`
WHERE `id` IN (' . $pageComponentsRight . ');');
$count = $db->affected_rows;
$i = 1;

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

$i++;
}
}
}
?>
The holy grail 3 column liquid Layout has been tested on
the following browsers:






query($sql);
$row = $db->fetch_row($result);

if ($db->affected_rows > 0)
{
# /components/footerlinks.inc.php
include(ROOT . $row[2]);
}

?>










Again, any questions/comments/critiques are welcome!!

Allen



On Wed, Jan 20, 2010 at 7:29 PM, Hendry  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
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 wrote:

> 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
>


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:

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
wrote:

> 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-28 Thread Allen McCabe
n functions is
> probably overkill, but some people like such midware.
> Your top-level class can take care of any caching of finished reports.
> Your superclass is responsible for building up the "frame" of the
> webpage that holds the reports.
> If two or more plugins need (almost) the same data, consider building
> a datastore 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 
> 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:
> >
> >  >
> > $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
> > wrote:
> >
> >> 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] 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
wrote:

> 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
>
>
>


[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).