Reply to Re: strange problem with php

Your name:

Reply:


Posted by Rik on 08/15/07 10:35

On Wed, 15 Aug 2007 12:26:42 +0200, Dave =

<david.greenhall@praybourne.co.uk> wrote:
> On 15 Aug, 11:06, Rik <luiheidsgoe...@hotmail.com> wrote:
>> On Wed, 15 Aug 2007 11:59:25 +0200, Dave
>> <david.greenh...@praybourne.co.uk> wrote:
>> > I have just set up a duplicate server running:
>> > apache 2.54, mysql 5.04 and php 5.04
>>
>> > This is the same setup as as the server we are using now, apart fro=
m
>> > the hardware inside. I have copied across the database and website,=

>> > with exact same permissions as the first server.
>>
>> > The problem is that part of the php code is executing but others
>> > arent:
>>
>> > example:
>> > ------------------------
>> > <?php
>> > die(mysql_error());
>> > echo "Connected to MySQL<br />";
>> > mysql_select_db("sales") or die(mysql_error());
>> > echo "Connected to Database<br />";
>>
>> > $query =3D mysql_query("SELECT product_name FROM `code_tbl` WHERE `=
code`
>> > =3D'P191")
>>
>> Shouldn't that be `code` =3D 'P191'" (notice the ending single quote)=
..
>>
>> > or die(mysql_error());
>>
>> > But when i change it to:
>> > -----------------
>> > <?php
>> > // Make the connection
>> > mysql_connect("localhost", "user", "pass") or die(mysql_error());
>> > echo "Connected to MySQL<br />";
>> > mysql_select_db("sales") or die(mysql_error());
>> > echo "Connected to Database<br />";
>>
>> > $query =3D mysql_query("SELECT product_name FROM `code_tbl` WHERE `=
code`
>> > =3D'$code")
>>
>> Again, the missing ending single quote in the SQL statement. Where do=
es
>> $code com form BTW? You're not relying on register_globals are you? N=
ot =

>> a
>> good thing. So, use $code =3D mysql_real_escape_string($_GET['code'])=
; =

>> first.
>>
>> > $result =3D mysql_fetch_array($query);
>>
>> var_dump($result);
>
> The missing ' was a mistype in the post. I have tried adding the code
> you suggested along with others.
>
> 1. adding the line $code =3D mysql_real_escape_string($_GET['code']);
> outputs absolutely nothing, not even "connected to database"

Have you enabled display_errors? It should be done just after connecting=
=

to the database.

> 2. Removing the single quotes around $code

You shouldn't do that.

> 3. Removing the last single quote from around $code (so becomes
> '$code ) like mistype above.

Shouldn't do that either.

> 4. When single quotes are put back in and adding the line
> var_dump($result);
> outputs: array(2) { [0]=3D> string(0) "" ["product_name"]=3D> string(0=
)
> "" }
>
> 5. When manually adding the code P191 in to the php code instead of
> $code, the ouput of var_dump is:
> array(2) { [0]=3D> string(28) "Pulsar Classic Bomber
> Jacket" ["product_name"]=3D> string(28) "Pulsar Classic Bomber Jacket"=
}

Well, echo the query that gets send before actually using it, and examin=
e =

where it differs.

-- =

Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация