Jump to content

mysql_fetch_array():


grrwood

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

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

}

?>

Link to comment
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.

Link to comment
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

Link to comment
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

 

Link to comment
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.