[PHP]MySQL error, what's wrong here..
the server is telling me line 43(which starts with $mp3d) is not a valid mysql result resource. what am i doing wrong?? chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP]MySQL error, what's wrong here..
Try: $query = "SELECT songname FROM mp3 WHERE sgid = '" .$id."'"; an SQL query requires you to quote strings. james -Original Message- From: Chris Cocuzzo [mailto:[EMAIL PROTECTED]] Sent: Monday, July 23, 2001 6:57 PM To: [EMAIL PROTECTED] Subject: [PHP]MySQL error, what's wrong here.. the server is telling me line 43(which starts with $mp3d) is not a valid mysql result resource. what am i doing wrong?? chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP]MySQL error, what's wrong here..
alright, new problem, no more errors, but there's just nothing...here's the code: and here's what the HTML code looks like from the page when i test it out.. http://www.fplg.net/stream.php?songid=2"; class="hov1"> what's going on with that... chris - Original Message - From: James Bogosian <[EMAIL PROTECTED]> To: Chris Cocuzzo <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Monday, July 23, 2001 7:25 PM Subject: RE: [PHP]MySQL error, what's wrong here.. > Try: > > $query = "SELECT songname FROM mp3 WHERE sgid = '" .$id."'"; > > an SQL query requires you to quote strings. > > james > > -Original Message- > From: Chris Cocuzzo [mailto:[EMAIL PROTECTED]] > Sent: Monday, July 23, 2001 6:57 PM > To: [EMAIL PROTECTED] > Subject: [PHP]MySQL error, what's wrong here.. > > >$id = rand(1,2); > $query = "SELECT songname FROM mp3 WHERE sgid = " .$id; > $result = mysql_query($query,$connection); > $mp3d = mysql_fetch_array($result); > ?> > > the server is telling me line 43(which starts with $mp3d) is not a valid > mysql result resource. what am i doing wrong?? > > chris > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP]MySQL error, what's wrong here..
In your code, you have the lines: -- while($mp3d = mysql_fetch_array($result)) { $mp3d = mysql_fetch_array($result); ?> -- In the while control structure, you are fetching a result into $mp3d, then inside the brackets, you fetch a second (non-existing) result into $mp3d again. Try it without the third line of that segment. james -Original Message- From: Chris Cocuzzo [mailto:[EMAIL PROTECTED]] Sent: Monday, July 23, 2001 7:39 PM To: [EMAIL PROTECTED] Subject: Re: [PHP]MySQL error, what's wrong here.. alright, new problem, no more errors, but there's just nothing...here's the code: and here's what the HTML code looks like from the page when i test it out.. http://www.fplg.net/stream.php?songid=2"; class="hov1"> what's going on with that... chris - Original Message - From: James Bogosian <[EMAIL PROTECTED]> To: Chris Cocuzzo <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Monday, July 23, 2001 7:25 PM Subject: RE: [PHP]MySQL error, what's wrong here.. > Try: > > $query = "SELECT songname FROM mp3 WHERE sgid = '" .$id."'"; > > an SQL query requires you to quote strings. > > james > > -Original Message----- > From: Chris Cocuzzo [mailto:[EMAIL PROTECTED]] > Sent: Monday, July 23, 2001 6:57 PM > To: [EMAIL PROTECTED] > Subject: [PHP]MySQL error, what's wrong here.. > > >$id = rand(1,2); > $query = "SELECT songname FROM mp3 WHERE sgid = " .$id; > $result = mysql_query($query,$connection); > $mp3d = mysql_fetch_array($result); > ?> > > the server is telling me line 43(which starts with $mp3d) is not a valid > mysql result resource. what am i doing wrong?? > > chris > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP]MySQL error, what's wrong here..
Chris Cocuzzo pressed the little lettered thingies in this order... > alright, new problem, no more errors, but there's just nothing...here's the > code: > > $query = "SELECT name FROM mp3 WHERE songid = '" .$id."'"; > > http://www.fplg.net/stream.php?songid=2"; class="hov1"> > Uhh... maybe I'm missing something here, but the URL supplies $songid and the query is getting $id. Unless your getting $id from somewhere other than the URL, you're going to be getting only results with an empty songid field. Another thing to try is to "or die" your query to check to see if the SQL syntax is OK: $result=mysql_query($query,$connection) or die(mysql_error()); Good luck... Christopher Ostmo a.k.a. [EMAIL PROTECTED] AppIdeas.com Innovative Application Ideas Meeting cutting edge dynamic web site needs since the dawn of Internet time (1995) Business Applications: http://www.AppIdeas.com/ Open Source Applications: http://open.AppIdeas.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP]MySQL error, what's wrong here..
maybe my sql syntax is completely wrong, but the "$id" part was a random number i generated, and then I was saying WHERE songid(which is the database field) is equal to $id. is that the wrong way? the reason why it's songid in that second tag is because I wanted the random number to indentify the song pulled from the database..so the database uses that number in the part where it says..."stream.php?songid= tell me if I need to clarify! chris - Original Message - From: Christopher Ostmo <[EMAIL PROTECTED]> To: Chris Cocuzzo <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Monday, July 23, 2001 10:38 PM Subject: Re: [PHP]MySQL error, what's wrong here.. > Chris Cocuzzo pressed the little lettered thingies in this order... > > > alright, new problem, no more errors, but there's just nothing...here's the > > code: > > > > $query = "SELECT name FROM mp3 WHERE songid = '" .$id."'"; > > > > http://www.fplg.net/stream.php?songid=2"; class="hov1"> > > > > Uhh... maybe I'm missing something here, but the URL supplies > $songid and the query is getting $id. Unless your getting $id from > somewhere other than the URL, you're going to be getting only results > with an empty songid field. Another thing to try is to "or die" your query > to check to see if the SQL syntax is OK: > $result=mysql_query($query,$connection) or die(mysql_error()); > > Good luck... > > Christopher Ostmo > a.k.a. [EMAIL PROTECTED] > AppIdeas.com > Innovative Application Ideas > Meeting cutting edge dynamic > web site needs since the > dawn of Internet time (1995) > > Business Applications: > http://www.AppIdeas.com/ > > Open Source Applications: > http://open.AppIdeas.com/ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP]MySQL error, what's wrong here..
On Tue, 24 Jul 2001 14:10, Chris Cocuzzo wrote: > > - Original Message - > From: Christopher Ostmo <[EMAIL PROTECTED]> > To: Chris Cocuzzo <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Monday, July 23, 2001 10:38 PM > Subject: Re: [PHP]MySQL error, what's wrong here.. > > > Chris Cocuzzo pressed the little lettered thingies in this order... > > > > > alright, new problem, no more errors, but there's just > > > nothing...here's > > the > > > > code: > > > > > > $query = "SELECT name FROM mp3 WHERE songid = '" .$id."'"; > > > > > > http://www.fplg.net/stream.php?songid=2"; class="hov1"> > > > > Uhh... maybe I'm missing something here, but the URL supplies > > $songid and the query is getting $id. Unless your getting $id from > > somewhere other than the URL, you're going to be getting only results > > with an empty songid field. Another thing to try is to "or die" your > > query > > > to check to see if the SQL syntax is OK: > > $result=mysql_query($query,$connection) or die(mysql_error()); > > > > Good luck... > > > maybe my sql syntax is completely wrong, but the "$id" part was a > random number i generated, and then I was saying WHERE songid(which is > the database field) is equal to $id. is that the wrong way? > > the reason why it's songid in that second tag is because I wanted > the random number to indentify the song pulled from the database..so > the database uses that number in the part where it > says..."stream.php?songid= > > tell me if I need to clarify! > chris Well. if the random number created is outside the range of actual songid values that are in the database, you're not going to get any rows returned, are you? You could confirm by echoing your query and trying the same query, with the randomly generated number, in the mysql console. Or by checking the number of rows returned by your query with mysql_num_rows() Incidentally, if songid is an int type, you don't want to pass it a value in quotes; only char types need to be quoted. -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA The Hubbell works fine; all that stuff IS blurry! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP]MySQL error, what's wrong here..
my guess would be that sgid is a character field. if this isn't the case then try hardcoding a known id into the query and seeing what happens. It could also be that the connection has failed, try something like: if ($connection = mysql_connect()) { ... $id = rand(1,2); $query = "SELECT songname FROM mp3 WHERE sgid = " .$id; if ($result = mysql_query($query,$connection)) { $mp3d = mysql_fetch_array($result); ... } else echo("query failed"); ... } else echo("connection failed"); this'll give you an idea of where it's going wrong Tim Ward Senior Systems Engineer Please refer to the following disclaimer in respect of this message: http://www.stivesdirect.com/e-mail-disclaimer.html > -Original Message- > From: Chris Cocuzzo [mailto:[EMAIL PROTECTED]] > Sent: 23 July 2001 23:57 > To: [EMAIL PROTECTED] > Subject: [PHP]MySQL error, what's wrong here.. > > >$id = rand(1,2); > $query = "SELECT songname FROM mp3 WHERE sgid = " .$id; > $result = mysql_query($query,$connection); > $mp3d = mysql_fetch_array($result); > ?> > > the server is telling me line 43(which starts with $mp3d) is > not a valid > mysql result resource. what am i doing wrong?? > > chris > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP]MySQL error, what's wrong here..
Hi Chris, If you're using MySQL 3.23+, you might want to consider using something like: SELECT songname FROM mp3 ORDER BY RAND() LIMIT 1 Not that this answers your original problem, but it seems to make more sense than manually coding a random number (which is, perhaps, impractical especiallyif you plan to add / take away entries to your table on a regular basis). James "Chris Cocuzzo" <[EMAIL PROTECTED]> wrote in message 014d01c113ca$dd3bf460$[EMAIL PROTECTED]">news:014d01c113ca$dd3bf460$[EMAIL PROTECTED]... >$id = rand(1,2); > $query = "SELECT songname FROM mp3 WHERE sgid = " .$id; > $result = mysql_query($query,$connection); > $mp3d = mysql_fetch_array($result); > ?> > > the server is telling me line 43(which starts with $mp3d) is not a valid > mysql result resource. what am i doing wrong?? > > chris > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP]MySQL error, what's wrong here..
try this: $query = "SELECT songname FROM mp3 WHERE sgid = \"$id\""; (or a little cleaner: $query = sprintf("SELECT songname FROM mp3 WHERE sgid = \"%d\"", $id); ) instead of: $query = "SELECT songname FROM mp3 WHERE sgid = " .$id; - Original Message - From: "James Holloway" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, July 24, 2001 11:05 AM Subject: Re: [PHP]MySQL error, what's wrong here.. > Hi Chris, > > If you're using MySQL 3.23+, you might want to consider using something > like: > > SELECT songname FROM mp3 ORDER BY RAND() LIMIT 1 > > Not that this answers your original problem, but it seems to make more sense > than manually coding a random number (which is, perhaps, impractical > especiallyif you plan to add / take away entries to your table on a regular > basis). > > James > > "Chris Cocuzzo" <[EMAIL PROTECTED]> wrote in message > 014d01c113ca$dd3bf460$[EMAIL PROTECTED]">news:014d01c113ca$dd3bf460$[EMAIL PROTECTED]... > > > $id = rand(1,2); > > $query = "SELECT songname FROM mp3 WHERE sgid = " .$id; > > $result = mysql_query($query,$connection); > > $mp3d = mysql_fetch_array($result); > > ?> > > > > the server is telling me line 43(which starts with $mp3d) is not a valid > > mysql result resource. what am i doing wrong?? > > > > chris > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]