Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

udp high ports, d-link extract firmware dsl-2750u, wwwwxxxxx.2G, yxxxcom, WWWXXX, ftp://192.168.100.100, wwwxxx 100, www.xxxcon, wwwxxx, oom killer misbehaves postgresql

Links

XODOX
Impressum

#1: Stumping Sql query...

Posted on 2008-04-22 23:20:06 by Guillaume Dargaud

I must be tired tonight:

$query="SELECT * FROM ImageList WHERE Name='$value[0]'";
$result=mysql_query($query, $DB) or die(mysql_error());
if ($result) {
$InContext=mysql_fetch_assoc($result);
echo $query;
print_r($InContext);
}
mysql_free_result($result);

No error but $InContext is always empty, although the $query as displayed
runs fine from PhpMyAdmin...
Something escapes me here.
--
Guillaume Dargaud
http://www.gdargaud.net/

Report this message

#2: Re: Stumping Sql query...

Posted on 2008-04-22 23:37:56 by sheldonlg

Guillaume Dargaud wrote:
> I must be tired tonight:
>
> $query="SELECT * FROM ImageList WHERE Name='$value[0]'";
> $result=mysql_query($query, $DB) or die(mysql_error());
> if ($result) {
> $InContext=mysql_fetch_assoc($result);
> echo $query;
> print_r($InContext);
> }
> mysql_free_result($result);
>
> No error but $InContext is always empty, although the $query as displayed
> runs fine from PhpMyAdmin...
> Something escapes me here.

$InContext is a row from the database. If you did var_dump($InContext)
would give you results, or if you display the contents of the row via
individual keys.

(I've looked at my own code like this many times and not seen it).

Report this message

#3: Re: Stumping Sql query...

Posted on 2008-04-23 01:59:26 by Jerry Stuckle

Guillaume Dargaud wrote:
> I must be tired tonight:
>
> $query="SELECT * FROM ImageList WHERE Name='$value[0]'";
> $result=mysql_query($query, $DB) or die(mysql_error());
> if ($result) {
> $InContext=mysql_fetch_assoc($result);
> echo $query;
> print_r($InContext);
> }
> mysql_free_result($result);
>
> No error but $InContext is always empty, although the $query as displayed
> runs fine from PhpMyAdmin...
> Something escapes me here.

Did you check the number of rows returned? It sounds like the query ran
OK, but no rows were returned (which is NOT an error).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Report this message

#4: Re: Stumping Sql query...

Posted on 2008-04-23 10:59:57 by Guillaume Dargaud

> Did you check the number of rows returned? It sounds like the query ran
> OK, but no rows were returned (which is NOT an error).


It indeed returns 0 row.

But if I run the SAME query (copy/pasted) into PhpMyAdmin, I get the
expected result.
I stared at those 4 lines of code all evening. I have identical lines in
other parts that work just fine.
--
Guillaume Dargaud
http://www.gdargaud.net/

Report this message

#5: Re: Stumping Sql query...

Posted on 2008-04-23 11:09:28 by luiheidsgoeroe

On Wed, 23 Apr 2008 10:59:57 +0200, Guillaume Dargaud
<use_the_form_on_my_contact_page@www.gdargaud.net> wrote:
>> Did you check the number of rows returned? It sounds like the query ran
>> OK, but no rows were returned (which is NOT an error).
>
> It indeed returns 0 row.
>
> But if I run the SAME query (copy/pasted) into PhpMyAdmin, I get the
> expected result.
> I stared at those 4 lines of code all evening. I have identical lines in
> other parts that work just fine.

- The same database? (Not for instance an more or less equal database with
an empty/other ImageList table?)
- Are you checking the query in the _source_ of the output? Watch out for
whitespace and the like.
--
Rik Wasmus

Report this message

#6: Re: Stumping Sql query...

Posted on 2008-04-23 14:03:01 by colin.mckinnon

On 23 Apr, 09:59, "Guillaume Dargaud"
<use_the_form_on_my_contact_p...@www.gdargaud.net> wrote:
> > Did you check the number of rows returned? It sounds like the query ran
> > OK, but no rows were returned (which is NOT an error).
>
> It indeed returns 0 row.
>
> But if I run the SAME query (copy/pasted) into PhpMyAdmin, I get the
> expected result.

You're not cutting and pasting from the code you showed us - which
never writes out the query and has interpolated variables in it.

C.

Report this message

#7: Re: Stumping Sql query...

Posted on 2008-04-23 15:12:08 by venti

> You're not cutting and pasting from the code you showed us - which
> never writes out the query and has interpolated variables in it.
>
> C.

I am assuming you are cutting and pasting the query into phpmyadmin
and then hard coding in an integer in place of the variable to test
the query. Otherwise it would barf.

Make sure that $value[0] is actually what you think it is by echoing
it prior to your if ($result) block -- or the converse, hard code an
integer into the php and try running it.

Report this message

#8: Re: Stumping Sql query...

Posted on 2008-04-23 16:02:12 by hellsop

On Wed, 23 Apr 2008 06:12:08 -0700 (PDT), venti wrote:
>
>> You're not cutting and pasting from the code you showed us - which
>> never writes out the query and has interpolated variables in it.
>>
>> C.
>
> I am assuming you are cutting and pasting the query into phpmyadmin
> and then hard coding in an integer in place of the variable to test
> the query. Otherwise it would barf.

It also doesn't show what $query contains at the time.

> Make sure that $value[0] is actually what you think it is by echoing
> it prior to your if ($result) block -- or the converse, hard code an
> integer into the php and try running it.

OP needs to print out the value of $query right after assembling it to
see what it ACTUALLY contains. I don't know exactly what's niggling at
me about the subscripted variable trying to get interpreted INSIDE the
quoted string like that, but I remember avoiding it often enough that it
looks odd when I read it. I've schooled myself to use dot-concat when
building queries for SOME reason and maybe that's it.

$query="SELECT * FROM ImageList WHERE Name='" . $value[0] . "'";

it more how I'd write it. But, I don't know why that looks more right to
me than the other way.

--
I got told by a friend's ex-girlfriend that she could tell I was
a Linux geek from the way I *walked*.
-- Skud

Report this message

#9: Re: Stumping Sql query...

Posted on 2008-04-23 16:38:11 by luiheidsgoeroe

On Wed, 23 Apr 2008 16:02:12 +0200, Peter H. Coffin =

<hellsop@ninehells.com> wrote:

> On Wed, 23 Apr 2008 06:12:08 -0700 (PDT), venti wrote:
>>
>>> You're not cutting and pasting from the code you showed us - which
>>> never writes out the query and has interpolated variables in it.
>>
>> I am assuming you are cutting and pasting the query into phpmyadmin
>> and then hard coding in an integer in place of the variable to test
>> the query. Otherwise it would barf.

Nope, strings would do too apparantly... Weird that, not having an integ=
er =

for a name...

> It also doesn't show what $query contains at the time.
>
>> Make sure that $value[0] is actually what you think it is by echoing
>> it prior to your if ($result) block -- or the converse, hard code an
>> integer into the php and try running it.
>
> OP needs to print out the value of $query right after assembling it to=

> see what it ACTUALLY contains.

And what does he do?

$query=3D"SELECT * FROM ImageList WHERE Name=3D'$value[0]'";
$result=3Dmysql_query($query, $DB) or die(mysql_error());
if ($result) {
$InContext=3Dmysql_fetch_assoc($result);
echo $query;
print_r($InContext);
}

Would that print the query? Yes it would (if it's valid), even with no =

rows in the resultset. Does he do what y'all ask? Yes, allready, save fo=
r =

giving us the exact output.
-- =

Rik Wasmus

Report this message

#10: Re: Stumping Sql query...

Posted on 2008-04-23 16:40:53 by Captain Paralytic

On 23 Apr, 14:02, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> but I remember avoiding it often enough that it
> looks odd when I read it. I've schooled myself to use dot-concat when
> building queries for SOME reason and maybe that's it.

That particular one SHOULD work OK. The troublesome ones are

"something $value[$n] something"

but this can be solved with:

"something {$value[$n]} something"

Report this message

#11: Re: Stumping Sql query...

Posted on 2008-04-23 17:37:36 by venti

I have identical lines in
other parts that work just fine.

Well, it's a longshot, but it's possible that you have an utf-8 / asci/
who knows mismatch. This can happen when you paste code from a
browser into an editor.

If you really have IDENTICAL code which gives you correct results,
then either erase the problem code, and paste in the working code, or
turn it into a function and call it.

Report this message

#12: Re: Stumping Sql query...

Posted on 2008-04-23 22:04:54 by Guillaume Dargaud

> $query="SELECT * FROM ImageList WHERE Name='$value[0]'";
> $result=mysql_query($query, $DB) or die(mysql_error());
> if ($result) {
> $InContext=mysql_fetch_assoc($result);
> echo $query;

The query gets printed here and it's (for instance):
SELECT * FROM ImageList WHERE Name='MaceTraverse'
which when fed straight into PhpMyAdmin returns:
Showing rows 0 - 0 (1 total, Query took 0.0004 sec)
MaceTraverse Climbing/Arizona/MaceTraverse.jpg Arizona

For reference the table is defined as
CREATE TABLE ImageList (
Name VARCHAR(100) NOT NULL,
Path VARCHAR(255) NOT NULL,
Source TEXT,
PRIMARY KEY (Name))

I just tried again after resetting Apache, and still no go.

If I add the following code to print everything:

$query="SELECT * FROM ImageList";
echo $query."|<BR>";
$result=mysql_query($query) or die(mysql_error());
while ($InContext=mysql_fetch_assoc($result)) { print_r($InContext); echo
"<BR>"; }
mysql_free_result($result);

Then among the output I DO get a line containing:
Array ( [Name] => MaceTraverse [Path] => Climbing/Arizona/MaceTraverse.jpg
[Source] => Arizona )


> print_r($InContext);
> }
> mysql_free_result($result);
>
> No error but $InContext is always empty, although the $query as displayed
> runs fine from PhpMyAdmin...
> Something escapes me here.
> --
> Guillaume Dargaud
> http://www.gdargaud.net/
>

Report this message

#13: Re: Stumping Sql query...

Posted on 2008-04-23 22:20:52 by luiheidsgoeroe

On Wed, 23 Apr 2008 22:04:54 +0200, Guillaume Dargaud =

<USE_MY_WEB_FORM@gdargaud.net> wrote:

>> $query=3D"SELECT * FROM ImageList WHERE Name=3D'$value[0]'";
>> $result=3Dmysql_query($query, $DB) or die(mysql_error());
>> if ($result) {
>> $InContext=3Dmysql_fetch_assoc($result);
>> echo $query;
>
> The query gets printed here and it's (for instance):
> SELECT * FROM ImageList WHERE Name=3D'MaceTraverse'
> which when fed straight into PhpMyAdmin returns:
> Showing rows 0 - 0 (1 total, Query took 0.0004 sec)
> MaceTraverse Climbing/Arizona/MaceTraverse.jpg Arizona
>
> For reference the table is defined as
> CREATE TABLE ImageList (
> Name VARCHAR(100) NOT NULL,
> Path VARCHAR(255) NOT NULL,
> Source TEXT,
> PRIMARY KEY (Name))
>
> I just tried again after resetting Apache, and still no go.
>
> If I add the following code to print everything:
>
> $query=3D"SELECT * FROM ImageList";
> echo $query."|<BR>";
> $result=3Dmysql_query($query) or die(mysql_error());
> while ($InContext=3Dmysql_fetch_assoc($result)) { print_r($InContext);=
echo
> "<BR>"; }
> mysql_free_result($result);
>
> Then among the output I DO get a line containing:
> Array ( [Name] =3D> MaceTraverse [Path] =3D> =

> Climbing/Arizona/MaceTraverse.jpg
> [Source] =3D> Arizona )

Which is NOT the formatting print_r will deliver if you view it in the =

source. It will have newlines.
Just, humor me, what happens if you do a $value[0] =3D trim($value[0]); =
=

before making the $query string? And if that still doesn't work, examine=
=

the _source_ of a possibly html browser you're using to check the query,=
=

and maybe check in a hex editor what the ascii values are.
-- =

Rik Wasmus

Report this message

#14: Re: Stumping Sql query...

Posted on 2008-04-23 22:36:59 by Guillaume Dargaud

> Just, humor me, what happens if you do a $value[0] = trim($value[0]);

Sure. Here's the modified code:

$value[0] = trim($value[0]);
echo "|$value[0]|<BR>";
$query="SELECT * FROM ImageList WHERE Name='$value[0]'";
echo $query."<BR>";
$result=mysql_query($query) or die(mysql_error());
if ($result) { $InContext=mysql_fetch_assoc($result); echo
"|$InContext|<BR>"; }
mysql_free_result($result);

It prints
|MaceTraverse|
SELECT * FROM ImageList WHERE Name='MaceTraverse'
||


> And if that still doesn't work, examine the _source_ of a possibly html
> browser

|<WBR>Mace<WBR>Traverse|<BR>SELECT * FROM ImageList WHERE
Name='<WBR>Mace<WBR>Traverse'<BR>||

Well, I guess you nailed it. I don't know what those <WBR> are doing there,
but they have no business in my nice query !!!

Thanks Rik and Co.
--
Guillaume Dargaud
http://www.gdargaud.net/

Report this message

#15: Re: Stumping Sql query...

Posted on 2008-04-23 23:01:50 by hellsop

On Wed, 23 Apr 2008 22:04:54 +0200, Guillaume Dargaud wrote:
>> $query="SELECT * FROM ImageList WHERE Name='$value[0]'";
>> $result=mysql_query($query, $DB) or die(mysql_error());
>> if ($result) {
>> $InContext=mysql_fetch_assoc($result);
>> echo $query;
>
> The query gets printed here and it's (for instance):
> SELECT * FROM ImageList WHERE Name='MaceTraverse'
> which when fed straight into PhpMyAdmin returns:
> Showing rows 0 - 0 (1 total, Query took 0.0004 sec)
> MaceTraverse Climbing/Arizona/MaceTraverse.jpg Arizona
>
> For reference the table is defined as
> CREATE TABLE ImageList (
> Name VARCHAR(100) NOT NULL,
> Path VARCHAR(255) NOT NULL,
> Source TEXT,
> PRIMARY KEY (Name))
>
> I just tried again after resetting Apache, and still no go.
>
> If I add the following code to print everything:
>
> $query="SELECT * FROM ImageList";
> echo $query."|<BR>";
> $result=mysql_query($query) or die(mysql_error());
> while ($InContext=mysql_fetch_assoc($result)) { print_r($InContext); echo
> "<BR>"; }
> mysql_free_result($result);
>
> Then among the output I DO get a line containing:
> Array ( [Name] => MaceTraverse [Path] => Climbing/Arizona/MaceTraverse.jpg
> [Source] => Arizona )

Great. It's working perfectly then. Your query fetches one row, into
array $InContext with named elements Name, Path, Source, which is
clearly not empty, and all is wonderful.

What problem are you having again?

>> print_r($InContext);
>> }
>> mysql_free_result($result);
>>
>> No error but $InContext is always empty, although the $query as displayed
>> runs fine from PhpMyAdmin...
>> Something escapes me here.
>> --
>> Guillaume Dargaud
>> http://www.gdargaud.net/
>>
>
>


--
4. Shooting is not too good for my enemies.
--Peter Anspach's list of things to do as an Evil Overlord

Report this message

#16: Re: Stumping Sql query...

Posted on 2008-04-23 23:03:32 by hellsop

On Wed, 23 Apr 2008 22:20:52 +0200, Rik Wasmus wrote:
> On Wed, 23 Apr 2008 22:04:54 +0200, Guillaume Dargaud
><USE_MY_WEB_FORM@gdargaud.net> wrote:
>
>>> $query="SELECT * FROM ImageList WHERE Name='$value[0]'";
>>> $result=mysql_query($query, $DB) or die(mysql_error());
>>> if ($result) {
>>> $InContext=mysql_fetch_assoc($result);
>>> echo $query;
>>
>> The query gets printed here and it's (for instance):
>> SELECT * FROM ImageList WHERE Name='MaceTraverse'
>> which when fed straight into PhpMyAdmin returns:
>> Showing rows 0 - 0 (1 total, Query took 0.0004 sec)
>> MaceTraverse Climbing/Arizona/MaceTraverse.jpg Arizona
>>
>> For reference the table is defined as
>> CREATE TABLE ImageList (
>> Name VARCHAR(100) NOT NULL,
>> Path VARCHAR(255) NOT NULL,
>> Source TEXT,
>> PRIMARY KEY (Name))
>>
>> I just tried again after resetting Apache, and still no go.
>>
>> If I add the following code to print everything:
>>
>> $query="SELECT * FROM ImageList";
>> echo $query."|<BR>";
>> $result=mysql_query($query) or die(mysql_error());
>> while ($InContext=mysql_fetch_assoc($result)) { print_r($InContext); echo
>> "<BR>"; }
>> mysql_free_result($result);
>>
>> Then among the output I DO get a line containing:
>> Array ( [Name] => MaceTraverse [Path] =>
>> Climbing/Arizona/MaceTraverse.jpg
>> [Source] => Arizona )
>
> Which is NOT the formatting print_r will deliver if you view it in the
> source. It will have newlines.

It'll looks like that if the output is being viewed in a browser. The
whole "<BR>" thing is a bit of a hint that this is the case.

> Just, humor me, what happens if you do a $value[0] = trim($value[0]);
> before making the $query string? And if that still doesn't work, examine
> the _source_ of a possibly html browser you're using to check the query,
> and maybe check in a hex editor what the ascii values are.


--
Either way, it'll remind the clued that there's only one letter
difference between 'turkey' and 'turnkey'.
-- Mike Andrews

Report this message

#17: Re: Stumping Sql query...

Posted on 2008-04-24 02:23:45 by sheldonlg

Guillaume Dargaud wrote:
>> $query="SELECT * FROM ImageList WHERE Name='$value[0]'";
>> $result=mysql_query($query, $DB) or die(mysql_error());
>> if ($result) {
>> $InContext=mysql_fetch_assoc($result);
>> echo $query;
>
> The query gets printed here and it's (for instance):
> SELECT * FROM ImageList WHERE Name='MaceTraverse'
> which when fed straight into PhpMyAdmin returns:
> Showing rows 0 - 0 (1 total, Query took 0.0004 sec)
> MaceTraverse Climbing/Arizona/MaceTraverse.jpg Arizona
>
> For reference the table is defined as
> CREATE TABLE ImageList (
> Name VARCHAR(100) NOT NULL,
> Path VARCHAR(255) NOT NULL,
> Source TEXT,
> PRIMARY KEY (Name))
>
> I just tried again after resetting Apache, and still no go.
>
> If I add the following code to print everything:
>
> $query="SELECT * FROM ImageList";
> echo $query."|<BR>";
> $result=mysql_query($query) or die(mysql_error());
> while ($InContext=mysql_fetch_assoc($result)) { print_r($InContext); echo
> "<BR>"; }
> mysql_free_result($result);
>
> Then among the output I DO get a line containing:
> Array ( [Name] => MaceTraverse [Path] => Climbing/Arizona/MaceTraverse.jpg
> [Source] => Arizona )
>
>
>> print_r($InContext);
>> }
>> mysql_free_result($result);
>>
>> No error but $InContext is always empty, although the $query as displayed
>> runs fine from PhpMyAdmin...
>> Something escapes me here.
>> --

I told you this before as the first reply to your post.
Try echoing $InContext['Path'] and $InContext['Source'] instead of
$InContext and see what happens.

$InContext is a ROW.

Report this message

#18: Re: Stumping Sql query...

Posted on 2008-04-24 09:45:33 by luiheidsgoeroe

On Thu, 24 Apr 2008 02:23:45 +0200, sheldonlg <sheldonlg> wrote:
>>> print_r($InContext);

> I told you this before as the first reply to your post.
> Try echoing $InContext['Path'] and $InContext['Source'] instead of
> $InContext and see what happens.

Please don't confuse the issue more because you don't know what print_r()
is.
--
Rik Wasmus

Report this message

#19: Re: Stumping Sql query...

Posted on 2008-04-24 13:09:50 by sheldonlg

Rik Wasmus wrote:
> On Thu, 24 Apr 2008 02:23:45 +0200, sheldonlg <sheldonlg> wrote:
>>>> print_r($InContext);
>
>> I told you this before as the first reply to your post.
>> Try echoing $InContext['Path'] and $InContext['Source'] instead of
>> $InContext and see what happens.
>
> Please don't confuse the issue more because you don't know what
> print_r() is.

I missed that. His original had "echo".

Report this message

#20: Re: Stumping Sql query...

Posted on 2008-04-24 13:15:39 by luiheidsgoeroe

On Thu, 24 Apr 2008 13:09:50 +0200, sheldonlg <sheldonlg> wrote:

> Rik Wasmus wrote:
>> On Thu, 24 Apr 2008 02:23:45 +0200, sheldonlg <sheldonlg> wrote:
>>>>> print_r($InContext);
>>
>>> I told you this before as the first reply to your post.
>>> Try echoing $InContext['Path'] and $InContext['Source'] instead of =

>>> $InContext and see what happens.
>> Please don't confuse the issue more because you don't know what =

>> print_r() is.
>
> I missed that. His original had "echo".

No, it didn't. His original echo'ed the query, and print_r'ed the result=
=

of mysql_fetch_assoc:

Message-ID: <aEsPj.3517$bf3.3281@news1.pds.libertysurf.fr>:
[quote]
I must be tired tonight:

$query=3D"SELECT * FROM ImageList WHERE Name=3D'$value[0]'";
$result=3Dmysql_query($query, $DB) or die(mysql_error());
if ($result) {
$InContext=3Dmysql_fetch_assoc($result);
echo $query;
print_r($InContext);
}
mysql_free_result($result);
[/quote]
-- =

Rik Wasmus

Report this message

#21: Re: Stumping Sql query...

Posted on 2008-04-24 16:04:15 by sheldonlg

Rik Wasmus wrote:
> On Thu, 24 Apr 2008 13:09:50 +0200, sheldonlg <sheldonlg> wrote:
>
>> Rik Wasmus wrote:
>>> On Thu, 24 Apr 2008 02:23:45 +0200, sheldonlg <sheldonlg> wrote:
>>>>>> print_r($InContext);
>>>
>>>> I told you this before as the first reply to your post.
>>>> Try echoing $InContext['Path'] and $InContext['Source'] instead of
>>>> $InContext and see what happens.
>>> Please don't confuse the issue more because you don't know what
>>> print_r() is.
>>
>> I missed that. His original had "echo".
>
> No, it didn't. His original echo'ed the query, and print_r'ed the result
> of mysql_fetch_assoc:
>
> Message-ID: <aEsPj.3517$bf3.3281@news1.pds.libertysurf.fr>:
> [quote]
> I must be tired tonight:
>
> $query="SELECT * FROM ImageList WHERE Name='$value[0]'";
> $result=mysql_query($query, $DB) or die(mysql_error());
> if ($result) {
> $InContext=mysql_fetch_assoc($result);
> echo $query;
> print_r($InContext);
> }
> mysql_free_result($result);
> [/quote]

You are correct. I read it too quickly and remembered correctly what I
had incorrectly read.

Report this message