grrwood Posted December 26, 2005 Share Posted December 26, 2005 ok lets see if i can explain this well. using a tutorial that can be found [a href=\"http://forum.overhauledpc.com/showthread.php?t=637\" target=\"_blank\"]here[/a] i compleated the 2 other tutorials no problem just added a line here and there but this one has got me. the error is as follow Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\easyphp\www\testplatform\profile.php on line 10 using a link like this [a href=\"http://localhost/testplatform/profile.php?u=1\" target=\"_blank\"]http://localhost/testplatform/profile.php?u=1[/a] the script is <?php // Connect to the database require("config.php"); // select database // Get users information $result = mysql_query("SELECT * FROM `users` WHERE `userid` = $u LIMIT 1"); [b]while($r=mysql_fetch_array($result)){[/b] // Turn breaks into new lines for biography field $r[biography] = nl2br($r[biography]); // Output users information echo "<b>Viewing $r[username]'s profile</b><br>"; echo "Biography: $r[biography]"; } ?> any help in this would be greatly appreatiated. as i have looked thourgh several sites tring to find the answer. then going through php databases with member listing to see how they pull up the members info. apache 1.3.33 php 4.3.10 mysql 4.1.9 Quote Link to comment https://forums.phpfreaks.com/topic/3100-mysql_fetch_array/ Share on other sites More sharing options...
tjhilder Posted December 26, 2005 Share Posted December 26, 2005 try this: <?php // Connect to the database require("config.php"); // select database // Get users information $result = mysql_query("SELECT * FROM `users` WHERE `userid` = $u LIMIT 1"); while($row = mysql_fetch_array($result)) { // Output users information echo "<b>Viewing {$row['username']}'s profile</b><br />"; echo nl2br("Biography: {$row['biography']}"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/3100-mysql_fetch_array/#findComment-10410 Share on other sites More sharing options...
fenway Posted December 26, 2005 Share Posted December 26, 2005 The only thing I can see is that you're not explicitly passing mysql_query() a link identifier, and since I don't see any code above line 10 that makes a DB call, it's possible that you're not connecting to the server properly. I bet if you check the value of $result after the query it will be FALSE, leading the error that you are reporting. Otherwise, $result should be a valid resource, and there should be no issues with the code above. Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/3100-mysql_fetch_array/#findComment-10415 Share on other sites More sharing options...
ryanlwh Posted December 26, 2005 Share Posted December 26, 2005 Have you tried $u = $_GET['u'] before passing it to the query? Quote Link to comment https://forums.phpfreaks.com/topic/3100-mysql_fetch_array/#findComment-10419 Share on other sites More sharing options...
grrwood Posted December 26, 2005 Author Share Posted December 26, 2005 thanks for the help i really appretiate it added the line if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } Error performing 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 'LIMIT 1' at line 1 so im going to keep reading hopefully something come up Quote Link to comment https://forums.phpfreaks.com/topic/3100-mysql_fetch_array/#findComment-10420 Share on other sites More sharing options...
LazyJones Posted December 26, 2005 Share Posted December 26, 2005 [!--quoteo(post=330466:date=Dec 26 2005, 02:23 PM:name=grrwood)--][div class=\'quotetop\']QUOTE(grrwood @ Dec 26 2005, 02:23 PM) 330466[/snapback][/div][div class=\'quotemain\'][!--quotec--] thanks for the help i really appretiate it added the line if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } Error performing 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 'LIMIT 1' at line 1 so im going to keep reading hopefully something come up I'm sure the problem is that variable $u is not set. Try it out by signing some value to it before query Quote Link to comment https://forums.phpfreaks.com/topic/3100-mysql_fetch_array/#findComment-10421 Share on other sites More sharing options...
grrwood Posted December 26, 2005 Author Share Posted December 26, 2005 you guys here in the forums are gods thank you. this works but like i butt head i could get it to work till i remembered the ; duh, oh well noob mistake $u = $_GET['u']; ended up leaving the code like this <?php // Connect to the database require("config.php"); // select database // Get users information $u = $HTTP_GET_VARS['u']; $result = mysql_query("SELECT * FROM `users` WHERE `userid` = $u LIMIT 1"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } while($r=mysql_fetch_array($result)){ // Turn breaks into new lines for biography field $r[biography] = nl2br($r[biography]); // Output users information echo "<b>Viewing $r[username]'s profile</b><br>"; echo "Biography: $r[biography]"; } ?> thanks again for the help you guys rock. and i will be sure to read more on _GET Quote Link to comment https://forums.phpfreaks.com/topic/3100-mysql_fetch_array/#findComment-10422 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.