Jump to content

Archived

This topic is now archived and is closed to further replies.

grrwood

mysql_fetch_array():

Recommended Posts

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

Share this post


Link to post
Share on other sites

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']}");

}

?>

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

[!--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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.