Re: [Phplib-users] Classes, MySQL, Images & phplib
Brought to you by:
nhruby,
richardarcher
From: nathan r. h. <na...@ds...> - 2001-12-31 21:38:33
|
On Mon, 31 Dec 2001, Frank Bax wrote: > Try: > function Image() { > global $GLOBALS; > $ID=$GLOBALS[ID]; > > Umm.. $GLOBALS[] is availible everywhere, isn't it? It's an alternative to the 'global' keyword? I just asked in openprojects:#php and someone remined me that paramters need to be static (eg: function foo($bar='something')) so Umm I did steer you wrong at first. Sorry. The class looks like it should work as you have it though.. er.. what's the calling script look like? I assume you're doing something like: include('/path/to/image.class'); $img = new Image; ? Right ;-) (Hey, it take me 10 minutes to figure out someone unpluged my computer :) So a few questions: - What php version are you using? - Where exactly does $ID come from? -n.. the nice thing about New Years Eve is that I can start drinking at 4 in the afternoon and not feel guility. Wheeeeeee! ps.. I'm going to make a side trip into proper coding styles becasue I see a lot of this (Ajay is guilty of this too, hence the parser warnings): PHP Interperts the following three statements differently: $array[foo] // foo is assumed to be a constant $array["foo"] // "foo" is scanned for variables to substitute before // executing the statsment $array['foo'] // foo is taken as a literal text string mixing and matching these just don't work, you need to be aware of what you're using. In your script you use $GLOBALS[ID] which makes php think that it should look for a constant named "ID" to use for substituion in the array, and fails. My expernice is that php normally makes the right choice and falls back to a varaible, but can give it the incorrect scope, hence your problems.. It pays to be extra pedantic about variable scope and importation becasue this is where most security issues come from, not to mention by not specficly telling php what kind ofvariable you're using, icky and hard to trace bugs (like this one) can be introduced. -n > >In anycase, the whole file now looks like this: > > > ><?php > >error_reporting(E_ALL); > >require('config.php3'); > > > >if ($debug && $HTTP_GET_VARS[breakme]) { > > echo "I'm outputing something to break the headers.<br>\n"; > > echo "This will allow me to see what exactly I'm sending.<br>\n"; > > echo "Including errors :)<br>\n"; > >} > > > >class Image { > > var $db; > > function Image() { > > $ID=$GLOBALS[ID]; > > $this->db = new proDB; > > echo "this isn't working"; > > $sql="SELECT photo FROM WLPphoto WHERE profileID='$ID'"; > > echo $this->db->nf(); > > $this->db->query($sql); > > while ($this->db->next_record()) { > > // Header("Content-type: image/jpeg"); > > print $this->db->Record['photo']; > > } > > } > >} > >?> > > -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- nathan hruby / digital statement na...@ds... http://www.dstatement.com/ Public GPG key can be found at: http://www.dstatement.com/nathan-gpg-key.txt ED54 9A5E 132D BD01 9103 EEF3 E1B9 4738 EC90 801B -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |