FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » cause of error is what?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
cause of error is what? [message #181567] Wed, 22 May 2013 01:44 Go to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
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>";

?>
Re: cause of error is what? [message #181568 is a reply to message #181567] Wed, 22 May 2013 01:54 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
Forgot to give the $number a value.
Re: cause of error is what? [message #181569 is a reply to message #181568] Wed, 22 May 2013 02:35 Go to previous messageGo to next message
David Robley is currently offline  David Robley
Messages: 23
Registered: March 2013
Karma: 0
Junior Member
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"
Re: cause of error is what? [message #181573 is a reply to message #181567] Wed, 22 May 2013 04:35 Go to previous messageGo to next message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
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.
Re: cause of error is what? [message #181574 is a reply to message #181573] Wed, 22 May 2013 10:25 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
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$8300dec7(at)news(dot)demon(dot)co(dot)uk>
Re: cause of error is what? [message #181576 is a reply to message #181574] Wed, 22 May 2013 12:34 Go to previous messageGo to next message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
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
>
>> 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
>

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
Re: cause of error is what? [message #181578 is a reply to message #181576] Wed, 22 May 2013 12:48 Go to previous messageGo to next message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
On 5/22/2013 5:34 AM, 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
>>
>>> 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
>>
>
> 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

Edit: 'sending a NULL value' (man I gotta have my coffee before posting)

> 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
Re: cause of error is what? [message #181582 is a reply to message #181573] Wed, 22 May 2013 17:03 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
On Tue, 21 May 2013 21:35:31 -0700, 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*
>
> 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.

FYI, 'id' IS defined as an integer and is the primary key.
Re: cause of error is what? [message #181585 is a reply to message #181576] Wed, 22 May 2013 21:05 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
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:Xns9FB6521286DB8invalidcom(at)94(dot)75(dot)214(dot)39>
Re: cause of error is what? [message #181586 is a reply to message #181582] Wed, 22 May 2013 23:42 Go to previous messageGo to next message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
On 5/22/2013 10:03 AM, richard wrote:
> On Tue, 21 May 2013 21:35:31 -0700, 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*
>>
>> 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.
>
> FYI, 'id' IS defined as an integer and is the primary key.
>

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
Re: cause of error is what? [message #181587 is a reply to message #181586] Thu, 23 May 2013 00:21 Go to previous messageGo to next message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma: 0
Senior Member
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
Re: cause of error is what? [message #181589 is a reply to message #181587] Thu, 23 May 2013 12:42 Go to previous messageGo to next message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
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
Re: cause of error is what? [message #181593 is a reply to message #181589] Thu, 23 May 2013 16:02 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
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, denismfmcmahon(at)gmail(dot)com
Re: cause of error is what? [message #181606 is a reply to message #181593] Thu, 23 May 2013 22:33 Go to previous message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
On 5/23/2013 9:02 AM, Denis McMahon wrote:
> 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.
>

Damn that Richard.....JK.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Google Voice App Comes To iPhone
Next Topic: use a value form a manu list in a form on the same page
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 03:58:15 GMT 2024

Total time taken to generate the page: 0.02566 seconds