php-general Digest 12 Mar 2007 09:11:33 -0000 Issue 4672

Topics (messages 250250 through 250273):

Re: Array mysteries
        250250 by: Robert Cummings

Using array_search I get error
        250251 by: Richard Kurth
        250252 by: Stut
        250253 by: Richard Kurth
        250255 by: Stut
        250257 by: Richard Kurth
        250271 by: Tijnema !

Re: PEAR not found
        250254 by: Chris

PHP 5.2 + IE 7 = HTTP 304 in login procedure
        250256 by: Yannick Warnier

php 4 and 5
        250258 by: edwardspl.ita.org.mo
        250259 by: Chris
        250260 by: Larry Garfield
        250261 by: Robert Cummings
        250272 by: Haydar Tuna

xml parsing
        250262 by: Marije van Deventer
        250263 by: Robert Cummings

Re: Why won't this query go through?
        250264 by: Jochem Maas
        250265 by: Myron Turner
        250273 by: Haydar Tuna

Re: My help with adding captcha
        250266 by: Chris

Re: Variable variables and references
        250267 by: Martin Alterisio

__autoload() no workie on my 5.2 install...
        250268 by: Nathan Hawks

Data Types Problem
        250269 by: Arno Coetzee
        250270 by: Satyam

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On Sun, 2007-03-11 at 21:41 +0100, Satyam wrote:
> ----- Original Message ----- 
> From: "Edward Vermillion" <[EMAIL PROTECTED]>
> To: "tedd" <[EMAIL PROTECTED]>
> Cc: "Tijnema !" <[EMAIL PROTECTED]>; <[email protected]>
> Sent: Sunday, March 11, 2007 8:57 PM
> Subject: Re: [PHP] Array mysteries
> 
> 
> >
> > On Mar 11, 2007, at 1:59 PM, tedd wrote:
> >
> >> At 12:02 PM -0500 3/11/07, Edward Vermillion wrote:
> >>> On Mar 11, 2007, at 10:02 AM, tedd wrote:
> >>>
> >>>> At 3:05 PM +0100 3/11/07, Tijnema ! wrote:
> >>>>> On 3/11/07, tedd <<mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED]>  wrote:
> >>>>>
> >>>>> At 10:05 AM +0100 3/11/07, Tijnema ! wrote:
> >>>>>>
> >>>>>> - You could define $wdays inside the function
> >>>>>> function convert_from_weekday ($weekday) {
> >>>>>> $wdays = array
> >>>>>>    (0 => "Sonntag"
> >>>>>>    ,1 => "Montag"
> >>>>>>    ,2 => "Dienstag"
> >>>>>>    ,3 => "Mittwoch"
> >>>>>>    ,4 => "Donnerstag"
> >>>>>>    ,5 => "Freitag"
> >>>>>>    ,6 => "Samstag"
> >>>>>>  );
> >>>>>>    return $wdays[$weekday];
> >>>>>>  }
> >>>>>> $day = convert_from_weekday(0) // $day = "Sonntag"
> >>>>>
> >>>>> Tijnema:
> >>>>>
> >>>>> That's also a shorter version of a simple switch statement.
> >>>>>
> >>>>> I haven't thought of, or seen, that before -- thanks.
> >>>>>
> >>>>> tedd
> >>>>>
> >>>>>
> >>>>> Yeah it is, but i just used moved his $wdays inside the function...
> >>>>>
> >>>>> but well, there are ofcourse a lot of other options, as date ("l") 
> >>>>> would also return the day of the month :)
> >>>>>
> >>>>> Tijnema
> >>>>
> >>>>
> >>>> It's the technique and not the specific data thing I was  addressing. 
> >>>> When I'm confronted with a case condition, I  typically use the switch 
> >>>> statement. But, your solution provided  me with another way to look at 
> >>>> that.
> >>>>
> >>>> Cheers,
> >>>>
> >>>> tedd
> >>>
> >>> But what's the cost of this in a loop, rebuilding the array each  time, 
> >>> as compared to a switch statement? Just another thought...
> >>>
> >>
> >>
> >>
> >> Ed
> >>
> >> It's just another way to look at a possible solution.
> >>
> >> As for the cost, what are we talking about? I doubt that a  "typical" 
> >> application would show any discernable difference in  execution times.
> >>
> >> One could test this easy enough by running both through 50k loops,  but 
> >> even then I doubt that the times would be that much different  -- but I 
> >> may be wrong, been there before.
> >>
> >> Cheers,
> >>
> >> tedd
> >
> > I don't know if there would be any difference either, which is why it  was 
> > a question.
> >
> > Although Larry's suggestion of making the array static is something I 
> > hadn't thought of.
> >
> > Overall it is an interesting concept to use an array instead of a  switch, 
> > and I do wonder at what point, if any, that the two would  start to 
> > diverge resource-wise.
> >
> > Would the array lookup be faster for a lesser-used option/key in a 
> > situation where there were quite a few options? (you wouldn't have to  go 
> > through the whole switch to get to the option at the end (?) or  would 
> > you? I have no idea how that all works internally)
> >
> Yes, you would.  It goes sequentially through each case:.  The array, on the 
> other hand, uses a hashing algorithm so it should be about even no matter 
> which option you pick.

Not quite. When the number of possible keys are small, a rote traversal
using language constructs such as if/elseif/else/case is likely to be
faster than incurring the overhead of the hash search. However, in
general the hash search will be faster. Having said that, the use of an
array to hold the key/value pairs produces a very succinct and readable
solution. Additionally, retrieval of such values from the database is
more easily implemented using the array methodology. For those not aware
of using static hash lookups with database results I've included an
example:

<?php

function convert_from_weekday( $weekday )
{
    static $days = null;

    if( $days === null )
    {
        $query =
            " SELECT "
            "    weekday_id "
            "    weekday_name "
            "FROM "
            "    weekday_table ";

        $days = array();
        if( $db->query( $query ) )
        {
            while( $db->nextRow() )
            {
                $days[$db->getField( 'weekday_id' )] =
                    $days[$db->getField( 'weekday_name' )];
            }
        }
    }

    if( isset( $days[$weekday] ) )
    {
        return $days[$weekday];
    }

    return null;
}

?>

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
This array comes from  $_REQUEST of all data submitted
 
$array='Array ( [id] => 17 [takeaction] => saveCustomFields [notes] => --
Feb 4, 2007 @ 9:16 PM --fdsfdsfsdfdsfsfsfds -- Feb 4, 2007 @ 9:21 PM
--fdfdsfsdffsd -- February 11, 2007, @ 9:31 PM -- This is a tes -- February
14, 2007, @ 10:10 PM -- jhafjhfa afjahfajfhda kasjdaksdhADSKJL [firstname]
=> NANCY [lastname] => ADKINS  [phone2] => [address1] => 25 ALWARD CT.
[address2] => [city] => MARTINSVILLE [State] => AK [other] => [zip] => 24112
[country] => US [date18] => 03-13-2007 [text19] => test1 [text20] =>
[rating] => 0 [status] => Active )';
 when I use array_search to find date18

$key = array_search('date18', $array);  // $key = 1;
 
I get Wrong datatype for second argument 
How come the array is wrong datatype isn't a array an array or am I using
this wrong

--- End Message ---
--- Begin Message ---
Richard Kurth wrote:
This array comes from  $_REQUEST of all data submitted
$array='Array ( [id] => 17 [takeaction] => saveCustomFields [notes] => --
Feb 4, 2007 @ 9:16 PM --fdsfdsfsdfdsfsfsfds -- Feb 4, 2007 @ 9:21 PM
--fdfdsfsdffsd -- February 11, 2007, @ 9:31 PM -- This is a tes -- February
14, 2007, @ 10:10 PM -- jhafjhfa afjahfajfhda kasjdaksdhADSKJL [firstname]
=> NANCY [lastname] => ADKINS  [phone2] => [address1] => 25 ALWARD CT.
[address2] => [city] => MARTINSVILLE [State] => AK [other] => [zip] => 24112
[country] => US [date18] => 03-13-2007 [text19] => test1 [text20] =>
[rating] => 0 [status] => Active )';
 when I use array_search to find date18

$key = array_search('date18', $array);  // $key = 1;
I get Wrong datatype for second argument How come the array is wrong datatype isn't a array an array or am I using
this wrong

$array is a string, and array_search is expecting an array, so it's correct. Where did you get that "array"?

-Stut

--- End Message ---
--- Begin Message ---
 

-----Original Message-----
From: Stut [mailto:[EMAIL PROTECTED] 
Sent: Sunday, March 11, 2007 2:53 PM
To: Richard Kurth
Cc: [email protected]
Subject: Re: [PHP] Using array_search I get error

Richard Kurth wrote:
> This array comes from  $_REQUEST of all data submitted
>  
> $array='Array ( [id] => 17 [takeaction] => saveCustomFields [notes] => 
> -- Feb 4, 2007 @ 9:16 PM --fdsfdsfsdfdsfsfsfds -- Feb 4, 2007 @ 9:21 
> PM --fdfdsfsdffsd -- February 11, 2007, @ 9:31 PM -- This is a tes -- 
> February 14, 2007, @ 10:10 PM -- jhafjhfa afjahfajfhda 
> kasjdaksdhADSKJL [firstname] => NANCY [lastname] => ADKINS  [phone2] =>
[address1] => 25 ALWARD CT.
> [address2] => [city] => MARTINSVILLE [State] => AK [other] => [zip] => 
> 24112 [country] => US [date18] => 03-13-2007 [text19] => test1 
> [text20] => [rating] => 0 [status] => Active )';  when I use 
> array_search to find date18
> 
> $key = array_search('date18', $array);  // $key = 1;
>  
> I get Wrong datatype for second argument How come the array is wrong 
> datatype isn't a array an array or am I using this wrong

$array is a string, and array_search is expecting an array, so it's correct.
Where did you get that "array"?

-Stut

This array comes from  $_REQUEST of all data submitted from a form

--- End Message ---
--- Begin Message ---
Richard Kurth wrote:
-----Original Message-----
From: Stut [mailto:[EMAIL PROTECTED] Sent: Sunday, March 11, 2007 2:53 PM
To: Richard Kurth
Cc: [email protected]
Subject: Re: [PHP] Using array_search I get error

Richard Kurth wrote:
This array comes from  $_REQUEST of all data submitted
$array='Array ( [id] => 17 [takeaction] => saveCustomFields [notes] => -- Feb 4, 2007 @ 9:16 PM --fdsfdsfsdfdsfsfsfds -- Feb 4, 2007 @ 9:21 PM --fdfdsfsdffsd -- February 11, 2007, @ 9:31 PM -- This is a tes -- February 14, 2007, @ 10:10 PM -- jhafjhfa afjahfajfhda kasjdaksdhADSKJL [firstname] => NANCY [lastname] => ADKINS [phone2] =>
[address1] => 25 ALWARD CT.
[address2] => [city] => MARTINSVILLE [State] => AK [other] => [zip] => 24112 [country] => US [date18] => 03-13-2007 [text19] => test1 [text20] => [rating] => 0 [status] => Active )'; when I use array_search to find date18

$key = array_search('date18', $array);  // $key = 1;
I get Wrong datatype for second argument How come the array is wrong datatype isn't a array an array or am I using this wrong

$array is a string, and array_search is expecting an array, so it's correct.
Where did you get that "array"?

-Stut

This array comes from  $_REQUEST of all data submitted from a form

Yeah, you said that in your first post. What I meant was where did it come from?

What you have there is the output from print_r($_REQUEST). How exactly are you getting that string? Why are you creating it as a literal array rather than using $_REQUEST directly?

-Stut

--- End Message ---
--- Begin Message ---

Richard Kurth wrote:
>  
> 
> -----Original Message-----
> From: Stut [mailto:[EMAIL PROTECTED]
> Sent: Sunday, March 11, 2007 2:53 PM
> To: Richard Kurth
> Cc: [email protected]
> Subject: Re: [PHP] Using array_search I get error
> 
> Richard Kurth wrote:
>> This array comes from  $_REQUEST of all data submitted
>>  
>> $array='Array ( [id] => 17 [takeaction] => saveCustomFields [notes] 
>> =>
>> -- Feb 4, 2007 @ 9:16 PM --fdsfdsfsdfdsfsfsfds -- Feb 4, 2007 @ 9:21 
>> PM --fdfdsfsdffsd -- February 11, 2007, @ 9:31 PM -- This is a tes -- 
>> February 14, 2007, @ 10:10 PM -- jhafjhfa afjahfajfhda 
>> kasjdaksdhADSKJL [firstname] => NANCY [lastname] => ADKINS  [phone2] 
>> =>
> [address1] => 25 ALWARD CT.
>> [address2] => [city] => MARTINSVILLE [State] => AK [other] => [zip] 
>> =>
>> 24112 [country] => US [date18] => 03-13-2007 [text19] => test1 
>> [text20] => [rating] => 0 [status] => Active )';  when I use 
>> array_search to find date18
>>
>> $key = array_search('date18', $array);  // $key = 1;
>>  
>> I get Wrong datatype for second argument How come the array is wrong 
>> datatype isn't a array an array or am I using this wrong
> 
> $array is a string, and array_search is expecting an array, so it's
correct.
> Where did you get that "array"?
> 
> -Stut
> 
> This array comes from  $_REQUEST of all data submitted from a form

Yeah, you said that in your first post. What I meant was where did it come
from?

What you have there is the output from print_r($_REQUEST). How exactly are
you getting that string? Why are you creating it as a literal array rather
than using $_REQUEST directly?

What you have there is the output from print_r($_REQUEST). How exactly are
you getting that string? Why are you creating it as a literal array rather
than using $_REQUEST directly?

-Stut

This is for saving data from custom fields created by the user I don't know
what they are named so I can't use $_REQUEST[name] to pull them from the
array.
I am submitting a form to a script that will search thru the array and find
the fields that are in there date18 text19 text20 these are user custom
fields that I do not know what they are named. I what to compare what is in
the array  with a database table and if they match then save the information
in the array for that item to the database.

--- End Message ---
--- Begin Message ---
On 3/12/07, Richard Kurth <[EMAIL PROTECTED]> wrote:



Richard Kurth wrote:
>
>
> -----Original Message-----
> From: Stut [mailto:[EMAIL PROTECTED]
> Sent: Sunday, March 11, 2007 2:53 PM
> To: Richard Kurth
> Cc: [email protected]
> Subject: Re: [PHP] Using array_search I get error
>
> Richard Kurth wrote:
>> This array comes from  $_REQUEST of all data submitted
>>
>> $array='Array ( [id] => 17 [takeaction] => saveCustomFields [notes]
>> =>
>> -- Feb 4, 2007 @ 9:16 PM --fdsfdsfsdfdsfsfsfds -- Feb 4, 2007 @ 9:21
>> PM --fdfdsfsdffsd -- February 11, 2007, @ 9:31 PM -- This is a tes --
>> February 14, 2007, @ 10:10 PM -- jhafjhfa afjahfajfhda
>> kasjdaksdhADSKJL [firstname] => NANCY [lastname] => ADKINS  [phone2]
>> =>
> [address1] => 25 ALWARD CT.
>> [address2] => [city] => MARTINSVILLE [State] => AK [other] => [zip]
>> =>
>> 24112 [country] => US [date18] => 03-13-2007 [text19] => test1
>> [text20] => [rating] => 0 [status] => Active )';  when I use
>> array_search to find date18
>>
>> $key = array_search('date18', $array);  // $key = 1;
>>
>> I get Wrong datatype for second argument How come the array is wrong
>> datatype isn't a array an array or am I using this wrong
>
> $array is a string, and array_search is expecting an array, so it's
correct.
> Where did you get that "array"?
>
> -Stut
>
> This array comes from  $_REQUEST of all data submitted from a form

Yeah, you said that in your first post. What I meant was where did it come
from?

What you have there is the output from print_r($_REQUEST). How exactly are
you getting that string? Why are you creating it as a literal array rather
than using $_REQUEST directly?

What you have there is the output from print_r($_REQUEST). How exactly are
you getting that string? Why are you creating it as a literal array rather
than using $_REQUEST directly?

-Stut

This is for saving data from custom fields created by the user I don't
know
what they are named so I can't use $_REQUEST[name] to pull them from the
array.
I am submitting a form to a script that will search thru the array and
find
the fields that are in there date18 text19 text20 these are user custom
fields that I do not know what they are named. I what to compare what is
in
the array  with a database table and if they match then save the
information
in the array for that item to the database.


Somehow you managed to get an array become a string..., if your are using
$_REQUEST directly, or a copy of it, then you should have an array.
I also don't really understand what you are trying to do, as 'date18' is a
key, not a value, and array_search searches vor values, in this case it
searches for the value 'date18' and then try's to get the key of that value,
but date18 is a key, so it would probably return false.

Tijnema

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



--- End Message ---
--- Begin Message ---
rwhartung wrote:
Hi all,
 I have a new install and am trying to get PEAR working - MDB2 to be exact.

I have modified /etc/php.ini to have the following

 include_path = ".:/php/includes:/usr/share/pear"

phpinfo() reports the directive --includedir=/usr/include

I can confirm that MDB2.php exists in that directory.
httpd has been restarted. I have literally copied the examples form the PEAR docs and I am using a postgresql backend using the bpsimple database that I can access with no problems with pg_connect() from a php script.

When using PEAR::MDB2 all I get is MDB2 Error:not found.

Ask on the pear list - http://pear.php.net/support/lists.php

and post the exact error message you're getting.. they will be able to help a lot more because they know the code base, we don't.

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Hello,

One of my clients is currently having a problem when logging into one of
my site.
Investigating further (because it works with Firefox with his login/pass
from my machine), it appears the problem is caused for an obscure reason
when IE7 requests the page and obviously does a "conditional GET", which
only loads what's necessary for this login to proceed when the page has
been updated since last time. The returned HTTP header is 304: Not
modified, which is not returned with other browsers (others get a 200
header).
This is true for PHP pages as well as included CSS files, which triggers
the question of having any link to PHP at all...

I've looked on Google quite a bit, and if I have found people having the
same kind of problems, they generally report it along with the fact that
they use incorrectly the header('HTTP/1.1 ...'); or
header('Status: ...'); function, so the fix is generally a change of
these.

However, my application doesn't set any of these headers from inside the
PHP code.

Before I start getting into the whole Apache2 config (which I'm not to
good at) and try a lot of funny things in a bid to discover one element
that would cause this, I'd like to know...

Does anybody know the problem and have already found a fix?

Thanks,

Yannick

--- End Message ---
--- Begin Message ---
Dear All,

What different between 4 and 5 ?

Edward.

--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
Dear All,

What different between 4 and 5 ?

http://www.php.net/manual/en/migration5.php#migration5.changes

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
On Sunday 11 March 2007 7:14 pm, [EMAIL PROTECTED] wrote:
> Dear All,
>
> What different between 4 and 5 ?
>
> Edward.

http://us2.php.net/manual/en/faq.migration5.php
http://us2.php.net/manual/en/migration5.php

Really, I normally am not an RTFMer, but it's not like the information isn't 
already presented to you on a silver platter.

-- 
Larry Garfield                  AIM: LOLG42
[EMAIL PROTECTED]               ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

--- End Message ---
--- Begin Message ---
On Mon, 2007-03-12 at 08:14 +0800, [EMAIL PROTECTED] wrote:
> Dear All,
> 
> What different between 4 and 5 ?

http://www.php.net/manual/en/migration5.php#migration5.changes

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Hello,
        Most important change is Object Oriented Features. PHP 5 support 
Object Oriented programming features. PHP 5 also supports more library than 
PHP 4.:)


-- 
Haydar TUNA
Republic Of Turkey - Ministry of National Education
Education Technology Department Ankara / TURKEY
Web: http://www.haydartuna.net


<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Dear All,
>
> What different between 4 and 5 ?
>
> Edward. 

--- End Message ---
--- Begin Message ---
I have been trying to parse this xml, and want to use it with childnodes 
<Label> and <Tekst>, but sofar due to the <li> and <p> and <image> elements no 
luck. How can i do this in a simple way ???

<?xml version="1.0" encoding="UTF-8"?>
<Menu>
 <Item>
  <Label>Algemeen</Label>
  <Tekst>aaaaaaaaaaaaaaaaaaaaaaaaaaaaa</Tekst>
 </Item>
 <Item>
  <Label>1-Atmosfeer</Label>
  <Tekst>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  <li>aaaaaaaaaaaaaaaaaaaaa</li>
  <li>bbbbbbbbbbbbbbbbbbbbbbbbbbb</li>
  <li>ccccccccccccccc</li>
  <li>dddddddddddddddddddddddddddddddddd</li>
  <img src="Saf2.jpg" alt="News" width="240" height="232"/><br /><br /><br 
/>qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq<br /><br /><br /></Tekst>
 </Item>
 <Item>
  <Label>Betrouwbare drukcabine</Label>
  <Tekst>ffffffffffffffffffffffffffffffff<img src="Saf3.jpg" alt="News" 
width="180" height="239"/><br /><br /><br /><br /><br /><br /><br /><br 
/>gggggggggggggggggggggggggggggggggggggggggggg<br /><br /><br /><br /><br /><br 
/></Tekst>
 </Item>
</Menu>

--- End Message ---
--- Begin Message ---
On Mon, 2007-03-12 at 01:38 +0100, Marije van Deventer wrote:
> I have been trying to parse this xml, and want to use it with
> childnodes <Label> and <Tekst>, but sofar due to the <li> and
> <p> and <image> elements no luck. How can i do this in a simple
> way ???

You're having trouble because the person who set the content of <Tekst>
didn't have a clue and so didn't mark up special entities. As such, the
XML has now taken on a mixed structure of XML and HTML.

You might have success performing the following before trying to parse:

<?php

    $xml = str_replace( '<Tekst>', '<Tekst><![CDATA[', $xml );
    $xml = str_replace( '</Tekst>', ']]></Tekst>', $xml );

?>

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Tijnema ! wrote:
> On 3/11/07, Mike Shanley <[EMAIL PROTECTED]> wrote:
>>
>> Hi,
>>
>> I am just not understanding what I could have possibly done wrong with
>> this query. All of the variables are good, without special characters in
>> any sense of the word... So why isn't it importing anything?
>>
>> Thanks!
>>
>> $q = "INSERT INTO
>>
>> `visitors`(`username`,`password`,`email`,`firstname`,`lastname`,`birthdate`,`verifythis`)
>>
>>                        VALUES ('".$username."',
>>                                '".md5($password1)."',
>>                                '".$email."',
>>                                '".$firstname."',
>>                                '".$lastname."',
>>                                '".$birthdate."',
>>                                '".$verifythis."');";

                                                    ^ -- oh my look at that, 
that's no good.

>> mysql_query($q);
> 
> 
> * me is gettings crazy!!! 

you haven't been here very long have you Tijnema.

> ALWAYS USE THE MYSQL_ERROR COMMAND!

indeed.

> mysql_query($q);
> becomes
> mysql_query($q) or die(mysql_error());

only my stance is that the above construction sucks, it makes for very brittle
code and there is nothing to say whether when this query fails the whole script
needs to die ... another thing is that when the sql breaks your giving the
[potential] evil haxor b'std all the information he needs to perform some kind 
of
sql injection attack.

I recommend logging the error, and/or using some kind of debug mode in addition 
to
a more sophistication approach to deciding if/when to exit the script.

but the basic advice sticks: check your return values and examine any/all 
relevant
error messages.

> then post the result of the error, or fix it by yourself when you know
> where
> the error is.
> 
> Tijnema
> 
> -- 
>> Mike Shanley
>>
>> ~you are almost there~

me? I've been there, smoked it and got the t-shirt to prove it.

--- End Message ---
--- Begin Message ---
Jochem Maas wrote:
Tijnema ! wrote:
On 3/11/07, Mike Shanley <[EMAIL PROTECTED]> wrote:
Hi,

I am just not understanding what I could have possibly done wrong with
this query. All of the variables are good, without special characters in
any sense of the word... So why isn't it importing anything?

Thanks!

$q = "INSERT INTO

`visitors`(`username`,`password`,`email`,`firstname`,`lastname`,`birthdate`,`verifythis`)

                       VALUES ('".$username."',
                               '".md5($password1)."',
                               '".$email."',
                               '".$firstname."',
                               '".$lastname."',
                               '".$birthdate."',
                               '".$verifythis."');";
Haven't you converted all of your columns to literals: 'username', etc, which should be plain username?

I find it's clearer to use the heredoc syntax:

$query= <<<QUERY
INSERT INTO visitors (username,password,email,firstname,lastname. . . etc)
VALUES($username,$password,$email . . . etc )
QUERY;



_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

--- End Message ---
--- Begin Message ---
Hello,
       Did you control your user privileges? May be, your database user 
don't have enough privileges for INSERT. If your database user have enough 
database privileges for INSERT, you must control your SQL. Firstly you 
should write your SQL to the screen with echo ($q) and then paste this in 
the mysql command line. If you get an errors, there is a problem on your 
SQL. :)


-- 
Haydar TUNA
Republic Of Turkey - Ministry of National Education
Education Technology Department Ankara / TURKEY
Web: http://www.haydartuna.net


"Mike Shanley" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi,
>
> I am just not understanding what I could have possibly done wrong with 
> this query. All of the variables are good, without special characters in 
> any sense of the word... So why isn't it importing anything?
>
> Thanks!
>
> $q = "INSERT INTO 
> `visitors`(`username`,`password`,`email`,`firstname`,`lastname`,`birthdate`,`verifythis`)
>                        VALUES ('".$username."',
>                                '".md5($password1)."',
>                                '".$email."',
>                                '".$firstname."',
>                                '".$lastname."',
>                                '".$birthdate."',
>                                '".$verifythis."');";
> mysql_query($q);
>
> -- 
> Mike Shanley
>
> ~you are almost there~ 

--- End Message ---
--- Begin Message ---
Joker7 wrote:
Hi- as you know I have been working on adding a captcha image to my guestbook. Well I have managed to get a very basic one working ;) but !I have been trying to get one that would make it more easy to use ,I have it working until I add it to my form.

My form use's print see below and I need to add this to it:


<img style="vertical-align: middle" src="<?php echo captchaImgUrl()?>">&nbsp;&nbsp;<input name="captcha" size="8"/>
<a href="<?php echo captchaWavUrl()?>">Listen To This</a>

And what happens when you try?

There's nothing in that snippet that shows an error (missing a semi-colon won't stop it printing as Tijnema suggested).


--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
2007/3/10, Dave Goodchild <[EMAIL PROTECTED]>:

Hi guys, I have just read 'Programming PHP' (O'Reilly) and although I
think
it's a great book, I am confused about variable variables and references -
not the mechanics, just where you would use them.

The subject of variable variables is explained but no examples are given
as
to why and where you would utilise them.


There really aren't useful and you're well without knowing they even exist.
In my opinion they harm code readibility, so they shouldn't be used,
especially if what you're trying to do can be achieved in some other way.

There is a special case where I found them useful. If you play competitions
like the sort of codegolf, they can be used to reduce your code by a few
characters by doing some really nasty things.

As for references, the examples given with regard to passing and returning
by reference in functions is clear, but no real examples are given as to
when this would be a preferred approcah - in fact, the authors stress that
due to PHP's copy-on-write mechanism, it is not a frequently-used
approcah.


References are useful to simulate PHP5 objects behaviour in PHP4. They can
be useful in many ways but I've found myself having too many troubles when
overusing them, segfaults and the sort...

So my question - are there any 'classic' situations in which either should
be used, and where and when do you guys use them in your real-world
efforts?
--
http://www.web-buddha.co.uk


--- End Message ---
--- Begin Message ---
Hey all.  This is my first post, 'coz it's the first time I've ever had
such a confusing problem with PHP.

I recently got a VPS and compiled PHP 5.2.1 with the following options:

--prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs
--with-config-file-path=/etc/php5 --with-curl
--with-curl-dir=/usr/local/lib --with-gd --with-gd-dir=/usr/local
--with-gettext --with-jpeg-dir=/usr/local/lib --with-kerberos
--with-mcrypt --with-mhash --with-mysql=/usr --with-pear
--with-png-dir=/usr/local/lib --with-xml --with-zlib
--with-zlib-dir=/usr/local/lib --with-zip --with-openssl --enable-bcmath
--enable-calendar --enable-ftp --enable-magic-quotes --enable-sockets
--enable-track-vars --enable-mbstring --enable-memory-limit
--with-freetype-dir=/usr/include/freetype2 --enable-soap
--with-mysql-sock=/tmp/mysql.sock

Apache is 2.2.4 and was also hand-compiled.

Meanwhile, at home, I have PHP 5.1.6 and Apache 2.2.3.

At home, __autoload() works great.

On the VPS, it doesn't work at all.

Here is a small case:
 = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
test.php:
<?php
function __autoload($classname) {
  include_once(dirname(__FILE__) . "/$classname.php");
}
$thinger = new foo();
echo $thinger->boo;
?>
 = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
foo.php:
<?php
class foo {
var $boo;
  function foo() {
    $this->boo = "I wouldn't say 'boo' if this autoloader worked on my
server...\n";
  }
}
?>
 = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
And, the crying begins:
[EMAIL PROTECTED] ~]$ php test.php

Fatal error: Cannot instantiate non-existent class:  foo
in /home/nhawks/test.php on line 5

Naturally for this simple test case, both files are in the same
directory.  

When I do the same thing at home...
[EMAIL PROTECTED] ~]$ php test.php
I wouldn't say 'boo' if this autoloader worked on my server...

I don't understand why __autoload() would fail, I didn't explicitly
enable it when compiling at home and I can't find anything via Google to
help ... 

No clues whatsoever in my Apache error_log.  When I try throwing:
echo("Got here!\n");
..into my __autoload() function, it reveals that __autoload() is never
being fired.

Please help.

Nathan

--- End Message ---
--- Begin Message ---
Hi Guys

I seem to have a problem with data types in php

when executing the following script , i do not get the desired output.

i a pass url parameter (message) to the script.

if i pass a numeric value (1) , the script accepts it as '01' and vice versa.
the same with 0 and '00'

here is the script:

<?php
   $theMessage = $_REQUEST['message'];
echo "theMessage : '" . $theMessage . "'\n"; if ($theMessage == "01")
   {
       echo "message : '01'";
   }else if ($theMessage == "00")
   {
       echo "message : '00'";
   }else if (is_numeric($theMessage))
   {
        echo "Numeric Input : " . $theMessage;
   }else
   {
       echo "Invalid Input";
   }
?>

i presume that i am not interpreting the data types it should be interpreted.

can anyone please help

--
Arno Coetzee
Flash Media Group
Developer
Mobile : 27 82 693 6180
Office : 27 12 430 7597

--- End Message ---
--- Begin Message --- Since in PHP you don't declare variable types, PHP does its best to guess what you mean with your values and integers have preference to strings, so your '01' gets converted to a plain integer 1 for the comparison.

Use === (triple) equal in the comparison and it will check for both value AND type and it won't do any type conversion.

Satyam


----- Original Message ----- From: "Arno Coetzee" <[EMAIL PROTECTED]>
To: "php-general" <[email protected]>
Sent: Monday, March 12, 2007 8:26 AM
Subject: [PHP] Data Types Problem


Hi Guys

I seem to have a problem with data types in php

when executing the following script , i do not get the desired output.

i a pass url parameter (message) to the script.

if i pass a numeric value (1) , the script accepts it as '01' and vice versa.
the same with 0 and '00'

here is the script:

<?php
   $theMessage = $_REQUEST['message'];
  echo "theMessage : '" . $theMessage . "'\n";
  if ($theMessage == "01")
   {
       echo "message : '01'";
   }else if ($theMessage == "00")
   {
       echo "message : '00'";
   }else if (is_numeric($theMessage))
   {
        echo "Numeric Input : " . $theMessage;
   }else
   {
       echo "Invalid Input";
   }
?>

i presume that i am not interpreting the data types it should be interpreted.

can anyone please help

--
Arno Coetzee
Flash Media Group
Developer
Mobile : 27 82 693 6180
Office : 27 12 430 7597

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



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.8/718 - Release Date: 11/03/2007 9:27



--- End Message ---

Reply via email to