Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cause of error is what?

7 views
Skip to first unread message

richard

unread,
May 21, 2013, 9:44:56 PM5/21/13
to
Can't get past the error message.
Could not run query: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near '' at line 1
www.mroldies.net/menu2.php


<?php

$year=$_GET["year"];
if (empty($year)) {$year=1900;}
$year=(int)$year;

/* connect to the db */
$con = mysql_connect('localhost','user','pass');


if (!$con){die("can not connect: " . mysql_error());}

mysql_select_db('richbull_top100',$con);

echo "<div style='clear:left;'>";

if ($year==1900){echo '<iframe width="1000" height="500" src="test2.php"
frameborder="0"></iframe>';}
else {echo $year."\n";

$result = mysql_query("SELECT atitle,artist,avid FROM A$year WHERE id =
$number");
if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; }
$vid = mysql_fetch_row($result);

echo $vid[0];

}

echo "</div>";

?>

richard

unread,
May 21, 2013, 9:54:48 PM5/21/13
to
Forgot to give the $number a value.

David Robley

unread,
May 21, 2013, 10:35:20 PM5/21/13
to
richard wrote:

> Forgot to give the $number a value.

Guess you didn't read my reply to your other question then
--
Cheers
David Robley

Iraq's national bird?, "DUCK"

Scott Johnson

unread,
May 22, 2013, 12:35:31 AM5/22/13
to
On 5/21/2013 6:44 PM, richard wrote:
> $result = mysql_query("SELECT atitle,artist,avid FROM A$year WHERE id =
> $number");
> if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; }
> $vid = mysql_fetch_row($result);
>
> echo $vid[0];
>
> }
>
> echo "</div>";
>
> ?>
>

*JTOL*

I could be wrong but..

Even if you left $number unset, that query should not of returned false
unless 'id' is not an (int) in your table definition.

Thomas 'PointedEars' Lahn

unread,
May 22, 2013, 6:25:10 AM5/22/13
to
Scott Johnson wrote:

> On 5/21/2013 6:44 PM, richard wrote:
>> $result = mysql_query("SELECT atitle,artist,avid FROM A$year WHERE id =
>> $number");
>> if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; }
>> $vid = mysql_fetch_row($result);
>>
>> echo $vid[0];
>>
>> }
>>
>> echo "</div>";
>>
>> ?>
>>
>
> *JTOL*

-v

> I could be wrong but..

You are. RTFMs.

> Even if you left $number unset, that query should not of returned false
> unless 'id' is not an (int) in your table definition.

$ php -r 'echo "foo" . @$number . "bar\n";'
foobar

If they left $number unset, it would be evaluated to NULL, expanded to the
zero-length string, and the query would be syntactical in error starting
from the last “=”.

mysql_query(), which is *deprecated*, returns FALSE if that happens or the
query cannot be executed for some other reason (which can be found out with
mysql_errorno() and mysql_error()). It *never* returns the result set such
as a field value; that has to be obtained by passing the “resource” value
returned by it as parameter to mysql_fetch_row() etc.

<http://php.net/mysql_query>

Also, MySQL implicitly converts numeric values to string values and vice-
versa. Suppose the `id` column of a table `foo` would be of the common type
“UNSIGNED INT(10, 0)”, both

SELECT * FROM `foo` WHERE `id` = 42

and

SELECT * FROM `foo` WHERE `id` = '42'

would *always* yield the same result set.

<http://dev.mysql.com/doc/refman/5.6/en/type-conversion.html> p.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300...@news.demon.co.uk>

Scott Johnson

unread,
May 22, 2013, 8:34:27 AM5/22/13
to
First off I have never been rude to you or anyone in this group so no
idea why you feel you need to 'RTFM' to me, but if you have to then you
have to.

My original thought/idea was that if 'id' was an (int) in the Db then
sending an empty value should not of caused a query error. But on
elaborating on the thought, there is much more to it when not having
$number set aside from the basic query. Stuff as simple as column set
to not accept NULL values, etc..

It was just a quick un-thought out thought (yes the existence of
un-thought can be argued), nothing more, nothing less.

Thanks however for expanding on the thought so as not to confuse anyone
reading it.

Scotty

Scott Johnson

unread,
May 22, 2013, 8:48:59 AM5/22/13
to
Edit: 'sending a NULL value' (man I gotta have my coffee before posting)

richard

unread,
May 22, 2013, 1:03:33 PM5/22/13
to
FYI, 'id' IS defined as an integer and is the primary key.

Thomas 'PointedEars' Lahn

unread,
May 22, 2013, 5:05:50 PM5/22/13
to
Scott Johnson wrote:

> On 5/22/2013 3:25 AM, Thomas 'PointedEars' Lahn wrote:
>> Scott Johnson wrote:
>>> On 5/21/2013 6:44 PM, richard wrote:
>>>> $result = mysql_query("SELECT atitle,artist,avid FROM A$year WHERE id =
>>>> $number");
>>>> if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; }
>>>> $vid = mysql_fetch_row($result);
>>>>
>>>> echo $vid[0];
>>>>
>>>> }
>>>>
>>>> echo "</div>";
>>>>
>>>> ?>
>>>>
>>>
>>> *JTOL*
>>
>> -v

So, what does “JTOL” mean?

>>> I could be wrong but..
>>
>> You are. RTFMs.
>>
>> […]
>> <http://php.net/mysql_query>
>> […]
>> <http://dev.mysql.com/doc/refman/5.6/en/type-conversion.html> p.
>
> First off I have never been rude to you or anyone in this group so no
> idea why you feel you need to 'RTFM' to me, but if you have to then you
> have to.

<http://www.catb.org/~esr/faqs/smart-questions.html#not_losing>

And please quote only the relevant parts. Time and space are precious
goods.

> My original thought/idea was that if 'id' was an (int) in the Db then
> sending an empty value should not of caused a query error. But on
> elaborating on the thought, there is much more to it when not having
> $number set aside from the basic query. Stuff as simple as column set
> to not accept NULL values, etc..

I do not follow. MySQL will never see a NULL value in this case. It will
see *no* value at all, causing a MySQL syntax error.

> It was just a quick un-thought out thought (yes the existence of
> un-thought can be argued), nothing more, nothing less.

Well, I for one try to test my assumptions before I post them, thereby not
wasting other people's time with such thoughts. Many things are
conceivable; few are well-founded.

> Thanks however for expanding on the thought so as not to confuse anyone
> reading it.

You're welcome, I think.


PointedEars
--
Sometimes, what you learn is wrong. If those wrong ideas are close to the
root of the knowledge tree you build on a particular subject, pruning the
bad branches can sometimes cause the whole tree to collapse.
-- Mike Duffy in cljs, <news:Xns9FB6521286...@94.75.214.39>

Scott Johnson

unread,
May 22, 2013, 7:42:59 PM5/22/13
to
I was just wondering because I have seen these issues in the past when I
am first coding and testing and some data does not populate properly.

It was a fleeting thought and nothing other.

Hope the rest of your project is moving forward.

Scotty

Beauregard T. Shagnasty

unread,
May 22, 2013, 8:21:41 PM5/22/13
to
Scott Johnson wrote:

> Hope the rest of your project is moving forward.

He's been working on it seems for about a decade now. You've seen the
results. It will never work sufficiently well enough to attract real
visitors.

--
-bts
-This space for rent, but the price is high

Scott Johnson

unread,
May 23, 2013, 8:42:27 AM5/23/13
to
On 5/22/2013 5:21 PM, Beauregard T. Shagnasty wrote:
> Scott Johnson wrote:
>
>> Hope the rest of your project is moving forward.
>
> He's been working on it seems for about a decade now. You've seen the
> results. It will never work sufficiently well enough to attract real
> visitors.
>

It did seem like he was given many good ideas on how to make his code
and application better but decided to ignore them.

I have rewritten so much code after looking thru so many of these NG
threads.

I am hopeful that as he runs into some serious issues (like when some of
the mysql extensions he is using are deprecated and removed), he will
see why many where giving him certain advice.

Scotty

Denis McMahon

unread,
May 23, 2013, 12:02:25 PM5/23/13
to
On Thu, 23 May 2013 05:42:27 -0700, Scott Johnson wrote:

> I am hopeful that as he runs into some serious issues (like when some of
> the mysql extensions he is using are deprecated and removed), he will
> see why many where giving him certain advice.

Or even when his site gets hacked and all his data is trashed, and then
it's used to serve kiddieporn, malware, and as part of a spamming botnet.

--
Denis McMahon, denismf...@gmail.com

Scott Johnson

unread,
May 23, 2013, 6:33:45 PM5/23/13
to
Damn that Richard.....JK.
0 new messages