[PHP-DB] What's wrong with this query?

2004-02-26 Thread Axel IS Main
I've just tried to do something I've done a thousand times. It does not 
work. I've checked all of the syntax, made sure the field and variable 
names are correct. No matter what I do it just doesn't work. The table 
remains empty. Here's the query:

$logit = mysql_query(INSERT INTO log SET term='$search', 
returns='$arrayword', time=CURTIME(), date=CURDATE(), ip='$ip');

Now that doesn't look too difficult does it? Well, apparently it's 
impossible! I'm really hoping someone out there can see something that I 
missed.

Nick

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


Re: [PHP-DB] What's wrong with this query?

2004-02-26 Thread Axel IS Main
Ok guys, I found the problem. It's actually something I've run into 
before. If you take a look at the query you'll notice that one of the 
fields is named returns. When I created the test table with phpMyAdmin 
it created it and everything seemed fine. Then I decided to try 
something. I tweaked my install script to add creation of the new log 
table and ran it. It failed on that field. When I changed the name of 
the field it worked. I've seen this before when I tried to create a 
field for another database called group. Apparently these are MySQL 
reserved words and you can't use them as names for fields. Go figure. 
Anyway, that solves the problem. When I run it the data is put into the 
table, and the line where I echo the $logit var displays a 1. By the 
way, I changed the name of the returns field to found.

Nick

Micah Stevens wrote:

Right.. a resource.. sorry. 

On Thursday 26 February 2004 12:55 pm, [EMAIL PROTECTED] wrote:
 

An interesting thought. I tried this:

echo Term: $search, Returns: $arrayword, UserIP: $ipbr;
$logit = mysql_query(INSERT INTO log SET term='$search',
returns='$arrayword', time=CURTIME(), date=CURDATE(), ip='$ip');
echo Query Value: $logit;
And got this on the page:

Term: skater, Returns: 312, UserIP: 192.168.1.234
Query Value:
-
mysql_query returns a Resource, which is not a printable 'string', You
could print_r($logit), or var_dump($logit) and you would most likely see
Resouce ID #3 (or some other number). So even if you're query excecutes
properly printing $logit will always show as you've written above.  The
same would hold true of an array, when just using print.
the returned value preceeds the function call in the manual.
from php.net/mysql_query
 resource mysql_query ( string query [, resource link_identifier])
hth
jeff
-
Notice that the variables are set with appropriate values, but the
$logit variable is blank. This, I think is the problem. The question is
why would it do this and not return any type of error? By the way, I
tried this using the other syntax people where suggesting and I got the
same results. I gotta tell you, this one is really kicking my ass. It's
the last piece of an update that I can't release until it's finished.
Nick

Hutchins, Richard wrote:
   

Been kind of following this thread off and on...

If the syntax is acceptable by MySQL, which it appears to be, is it
 

possible

   

that the variables you are using within the query string are not set to
anything? Or is it possible that there is something broken immediately
before the query string is fired?
Most times, when I run into query problems, immediately before I send the
query to the database, I'll echo the statement out to the browser so I can
see the exact string that's being sent to the db.
So can you do this:

$sql = INSERT INTO log SET term='$search', returns='$arrayword',
time=CURTIME(), date=CURDATE(), ip='$ip';
echo $sql;

$logit = mysql_query($sql) or
  die(mysql_error());
And check out what gets spit out to the browser when $sql is echoed? Maybe
that'll point out something that's going wrong. If nothing is apparent,
 

post

   

the results of echo $sql back to the list and maybe one of us will find
something.
HTH.

Rich

 

-Original Message-
From: Axel IS Main [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 26, 2004 2:37 PM
To: PHP DB
Subject: Re: [PHP-DB] What's wrong with this query?
Ok, ok. I get the message about the syntax. Since I've used
this syntax
for a long time and so far there hasn't been a problem I'll assume
that's not the problem. I will, however, review this and
probably make
some changes for the sake of compliance if nothing else. In
any event,
the syntax is NOT why it is failing, smart ass comments by people who
think two years is a long time not withstanding.
As to the useful questions that where asked. There is no
error reported.
Error reporting is set to E_ALL  ~E_NOTICE. I removed the
notice part
so I would get everything and still nothing showed up. I'm
also logging
errors and nothing is showing up in the log either. Not all PHP/MySQL
errors are reported. Sometimes what happens is not considered
an error,
even though it does not do what you would expect it to do. If
the query
syntax was wrong, I would get a syntax error. There is no
error, it just
doesn't write to the table. I can go into phpMyAdmin and with
the same
syntax insert into the table all day long.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
   

 



Re: [PHP-DB] What's wrong with this query?

2004-02-26 Thread Axel IS Main
Actually, yes, a thousand times is an obvious exaggeration, but I have 
done a whole lot of times, and the query syntax is the query syntax. 
Different don't make it wrong. This is working in several other places 
throughout this particular set of scripts.

Paul Fitz wrote:

You haven't done that a thousand times - the syntax is wrong :).
You are using a combo of INSERT and UPDATE syntax there.
Try 

INSERT INTO log (term, returns, time, date, ip) VALUES ('$search',
'$arrayword',CURTIME(), CURDATE(), '$ip');
Cheers,
Paul


-Original Message-
From: Axel IS Main [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 26, 2004 7:06 PM
To: PHP-DB
Subject: [PHP-DB] What's wrong with this query?

I've just tried to do something I've done a thousand times. It does not 
work. I've checked all of the syntax, made sure the field and variable 
names are correct. No matter what I do it just doesn't work. The table 
remains empty. Here's the query:

$logit = mysql_query(INSERT INTO log SET term='$search', 
returns='$arrayword', time=CURTIME(), date=CURDATE(), ip='$ip');

Now that doesn't look too difficult does it? Well, apparently it's 
impossible! I'm really hoping someone out there can see something that I

missed.

Nick

 

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


Re: [PHP-DB] What's wrong with this query?

2004-02-26 Thread Axel IS Main
An interesting thought. I tried this:

echo Term: $search, Returns: $arrayword, UserIP: $ipbr;
$logit = mysql_query(INSERT INTO log SET term='$search', 
returns='$arrayword', time=CURTIME(), date=CURDATE(), ip='$ip');
echo Query Value: $logit;

And got this on the page:

Term: skater, Returns: 312, UserIP: 192.168.1.234
Query Value:
Notice that the variables are set with appropriate values, but the 
$logit variable is blank. This, I think is the problem. The question is 
why would it do this and not return any type of error? By the way, I 
tried this using the other syntax people where suggesting and I got the 
same results. I gotta tell you, this one is really kicking my ass. It's 
the last piece of an update that I can't release until it's finished.

Nick

Hutchins, Richard wrote:

Been kind of following this thread off and on...

If the syntax is acceptable by MySQL, which it appears to be, is it possible
that the variables you are using within the query string are not set to
anything? Or is it possible that there is something broken immediately
before the query string is fired?
Most times, when I run into query problems, immediately before I send the
query to the database, I'll echo the statement out to the browser so I can
see the exact string that's being sent to the db.
So can you do this:

$sql = INSERT INTO log SET term='$search', returns='$arrayword',
time=CURTIME(), date=CURDATE(), ip='$ip';
echo $sql;

$logit = mysql_query($sql) or
die(mysql_error());
And check out what gets spit out to the browser when $sql is echoed? Maybe
that'll point out something that's going wrong. If nothing is apparent, post
the results of echo $sql back to the list and maybe one of us will find
something.
HTH.

Rich

 

-Original Message-
From: Axel IS Main [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 26, 2004 2:37 PM
To: PHP DB
Subject: Re: [PHP-DB] What's wrong with this query?
Ok, ok. I get the message about the syntax. Since I've used 
this syntax 
for a long time and so far there hasn't been a problem I'll assume 
that's not the problem. I will, however, review this and 
probably make 
some changes for the sake of compliance if nothing else. In 
any event, 
the syntax is NOT why it is failing, smart ass comments by people who 
think two years is a long time not withstanding.

As to the useful questions that where asked. There is no 
error reported. 
Error reporting is set to E_ALL  ~E_NOTICE. I removed the 
notice part 
so I would get everything and still nothing showed up. I'm 
also logging 
errors and nothing is showing up in the log either. Not all PHP/MySQL 
errors are reported. Sometimes what happens is not considered 
an error, 
even though it does not do what you would expect it to do. If 
the query 
syntax was wrong, I would get a syntax error. There is no 
error, it just 
doesn't write to the table. I can go into phpMyAdmin and with 
the same 
syntax insert into the table all day long.

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

 



Re: [PHP-DB] What's wrong with this query?

2004-02-26 Thread Axel IS Main
Ok, ok. I get the message about the syntax. Since I've used this syntax 
for a long time and so far there hasn't been a problem I'll assume 
that's not the problem. I will, however, review this and probably make 
some changes for the sake of compliance if nothing else. In any event, 
the syntax is NOT why it is failing, smart ass comments by people who 
think two years is a long time not withstanding.

As to the useful questions that where asked. There is no error reported. 
Error reporting is set to E_ALL  ~E_NOTICE. I removed the notice part 
so I would get everything and still nothing showed up. I'm also logging 
errors and nothing is showing up in the log either. Not all PHP/MySQL 
errors are reported. Sometimes what happens is not considered an error, 
even though it does not do what you would expect it to do. If the query 
syntax was wrong, I would get a syntax error. There is no error, it just 
doesn't write to the table. I can go into phpMyAdmin and with the same 
syntax insert into the table all day long.

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


[PHP-DB] Strange DB Error

2004-02-25 Thread Axel IS Main
When returning to the main page of my script sometimes I'll get the 
following error:

Warning: mysql_fetch_array(): 8 is not a valid MySQL result resource in 
/home/nick/http/search/includes/main.inc on line 13

This happens only AFTER the first element in the resource has been 
processed. Here's the code that is causing the problem:

$s = mysql_query(SELECT * FROM categories WHERE length(cat)='2');
while($t = mysql_fetch_array($s)){
   $cat = $t[cat];
   $name = $t[name];
   if($tstruc == $dirwidth){
   echo /trtr;
   $tstruc = 0;
   }
   echo td align=\left\ valign=\top\font face=\verdana,sans 
serif,helvetica\ size=\3\ba 
href=\index.php?index=directory.inccat=$catname=$namedepth=0\$name/a/b/font;
   $subcat = mysql_unbuffered_query(SELECT * FROM categories WHERE 
length(cat)='4'  substring(cat,1,2)='$cat' ORDER BY cat);
   while($ct = mysql_fetch_array($subcat)){
   $scats = $ct[name];
   $dcats = $dcats . $scats . ,  ;
   }
   $dcats = trim(substr($dcats, 0, 28)) . trim(...);
   if($dcats != ...){
   echo brfont face = \tahoma,sans serif,helvetica\ 
size=\1\ . $dcats . /font;
   }
   $dcats = ;
   echo /td;
   ++$tstruc;
}

You can go to the site http://www.icesource.com to see this script in 
action. This is an intermittent problem so you may not see it at the 
site, but it does happen there sometimes. If you click on one of the 
categories on the list there, and to two or three deep, then hit the 
Home link at the top left of the listings there's a pretty good chance 
you'll see the problem. I've been trying to figure this out for a long 
time, and nothing seems to work. Any ideas out there would be greatly 
appreciated.

Nick


Re: [PHP-DB] Strange DB Error

2004-02-25 Thread Axel IS Main
Error trapping is not really relevant here as the server is properly 
configured so the errors are going to show up in either event. In fact, 
using the die() function on my server just makes thing worse. In any 
case, the var_dump was a good idea as I was able to find out that what 
is happening is when this loops up after the first run through the array 
is blank. It doesn't reinitialize the array with the new values. As far 
as the $cat, or any of the other variables go, they're always the same 
when returning to the index. Whether I initialize them from the query 
string, or in the index itself as in the case when it is loaded without 
any parameters. The question is, why wouldn't the array be redefined on 
the second loop? Hell if I know.

Nick

[EMAIL PROTECTED] wrote:



 

When returning to the main page of my script sometimes I'll get the
following error:
   

 

Warning: mysql_fetch_array(): 8 is not a valid MySQL result resource in
/home/nick/http/search/includes/main.inc on line 13
   

 

This happens only AFTER the first element in the resource has been
processed. Here's the code that is causing the problem:
   

First, i'd place an... or die (mysql_error()) after your mysql call.  so
you can see what mysql is complaining about.  basically your sql is
failing.  I also like to split the first two items, when debegging, to see
what the actual query was.  i.e.
psedocode
$qry = SELECT * FROM categories WHERE length(cat)='2';
$s = mysql_query($qry) or die (mysql_error() . \nbr . $qry .
\nbr);
psedocode

The only time i saw the error on your page the 'cat' GET variable was
defined as 0.  Is this really a static query like below, or is it based on
what is passed to the page in the query string?  The URL when it died...
http://www.icesource.com/index.php?depth=0cat=0index=main.inc, which to
me looks like a bad querystring, but may indeed be valid values.

If that doesn't lend itself to any useful information, try var_dump($t); in
your while loop, to see what has been processed and what is failing.
HTH
Jeff
 

$s = mysql_query(SELECT * FROM categories WHERE length(cat)='2');
while($t = mysql_fetch_array($s)){$cat = $t[cat];
  $name = $t[name];
  if($tstruc == $dirwidth){echo /trtr;
  $tstruc = 0;
  }
  echo td align=\left\ valign=\top\font face=\verdana,sans
serif,helvetica\ size=\3\ba
href=\index.php?index=directory.inccat=$catname=$namedepth=0\$name/a/b/font;
   

 

  $subcat = mysql_unbuffered_query(SELECT * FROM categories WHERE
length(cat)='4'  substring(cat,1,2)='$cat' ORDER BY cat);
  while($ct = mysql_fetch_array($subcat)){$scats
   

= $ct[name];
 

  $dcats = $dcats . $scats . ,  ;
  }
  $dcats = trim(substr($dcats, 0, 28)) . trim(...);
  if($dcats != ...){echo brfont face = \tahoma,sans
   

serif,helvetica\
 

size=\1\ . $dcats . /font;
  }
  $dcats = ;
  echo /td;
  ++$tstruc;
}
   

 

You can go to the site http://www.icesource.com to see this script in
action. This is an intermittent problem so you may not see it at the
site, but it does happen there sometimes. If you click on one of the
categories on the list there, and to two or three deep, then hit the
Home link at the top left of the listings there's a pretty good chance
you'll see the problem. I've been trying to figure this out for a long
time, and nothing seems to work. Any ideas out there would be greatly
appreciated.
   

 

Nick
   

 



[PHP-DB] Re:[PHP-DB] Strange DB Error

2004-02-25 Thread Axel IS Main
What you propose makes sense of course, but no matter what I do, where I 
send the errors, even to the system log, the mysql_fetch_array () error 
is the only one that shows up. It would appear that either the query is 
failing is some way that PHP isn't recognizing, or the fetch isn't 
working properly. It could also be that for whatever reason, the query 
isn't finding all of the records that meet the criteria. I've tried 
doing and unconditional SELECT from the database but that had no effect 
on this error. I still got it. This is not the only place I look at this 
database, but it is the only place I get this error.

Nick

[EMAIL PROTECTED] wrote:

  
  
  







 

Error trapping is not really relevant here as the server is properly
   

configured so the errors are going to show up in either event. In fact,
using the die() function on my server just makes thing worse.
---
it'll definitely make it worse, but hopefully only to find the problem and
make it better.  you should be able to find the query on which this is not
a valid resource run that agains't mysql and find out why its failing,
if you can't see that from $qry being in die().  but yes, a bad idea in
production.   send the output to a file on error and see what your
getting.the error that you want is from mysql_query, the error that you're
showing is from mysql_fetch_array(), so if the server is configured to show
them elsewhere then the answer should be right before the error below
hth
jeff
In any case, the var_dump was a good idea as I was able to find out that
what is happening is when this loops up after the first run through the
array is blank. It doesn't reinitialize the array with the new values. As
far as the $cat, or any of the other variables go, they're always the same
when returning to he index. Whether I initialize them from the query
string, or in the index itself as in the case when it is loaded without any
parameters. The question is, why wouldn't the array be redefined on the
second loop? Hell if I know.
Nick

[EMAIL PROTECTED] wrote:





   When returning to the main page of my script sometimes I'll get
   the
   following error:


   Warning: mysql_fetch_array(): 8 is not a valid MySQL result
   resource in
   /home/nick/http/search/includes/main.inc on line 13


   This happens only AFTER the first element in the resource has
   been
   processed. Here's the code that is causing the problem:
 First, i'd place an... or die (mysql_error()) after your mysql call.
 so
 you can see what mysql is complaining about.  basically your sql is
 failing.  I also like to split the first two items, when debegging,
 to see
 what the actual query was.  i.e.
 psedocode
 $qry = SELECT * FROM categories WHERE length(cat)='2';
 $s = mysql_query($qry) or die (mysql_error() . \nbr . $qry .
 \nbr);
 psedocode
 The only time i saw the error on your page the 'cat' GET variable was
 defined as 0.  Is this really a static query like below, or is it
 based on
 what is passed to the page in the query string?  The URL when it
 died...
 http://www.icesource.com/index.php?depth=0cat=0index=main.inc,
 which to
 me looks like a bad querystring, but may indeed be valid values.


 If that doesn't lend itself to any useful information, try
 var_dump($t); in
 your while loop, to see what has been processed and what is failing.
 HTH
 Jeff
   $s = mysql_query(SELECT * FROM categories WHERE
   length(cat)='2');
   while($t = mysql_fetch_array($s)){$cat = $t[cat];
  $name = $t[name];
  if($tstruc == $dirwidth){echo /trtr;
  $tstruc = 0;
  }
  echo td align=\left\ valign=\top\font
   face=\verdana,sans
   serif,helvetica\ size=\3\ba
   
href=\index.php?index=directory.inccat=$catname=$namedepth=0\$name/a/b/font;


  $subcat = mysql_unbuffered_query(SELECT * FROM categories
   WHERE
   length(cat)='4'  substring(cat,1,2)='$cat' ORDER BY cat);
  while($ct = mysql_fetch_array($subcat)){$scats
 = $ct[name];

  $dcats = $dcats . $scats . ,  ;
  }
  $dcats = trim(substr($dcats, 0, 28)) . trim(...);
  if($dcats != ...){echo brfont face
   = \tahoma,sans
 serif,helvetica\

   size=\1\ . $dcats . /font;
  }
  $dcats = ;