Jump to content

[SOLVED] mysql_fetch_array() problem


Wildhalf

Recommended Posts

Hi,

I need help.. I designed my site on my local pc testing my php with xampp... Everything was working fine but now that i have uploaded my site it get the following error message...

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

the code is as follows...
*************************

// Get database connection
include 'db.php';

// Create variables from URL.
$refer_id = $_REQUEST['id'];

//If domain is visited without a refer the site uses the following
if ($refer_id == "")
{  $refer_id = 75645361;
}

//retrieves information from database...
$sql = mysql_query("SELECT * FROM tblFriends WHERE myspace_id='$refer_id'");

$data = mysql_fetch_array($sql); -->Line that is causing the problem

//adds array information to a variable
$friend_1 = $data[friend_1];
$friend_2 = $data[friend_2];
$friend_3 = $data[friend_3];
$friend_4 = $data[friend_4];
$friend_5 = $data[friend_5];
$friend_6 = $data[friend_6];

/* Let's strip some slashes in case the user entered
any escaped characters. */
$friend_id = stripslashes($friend_id);
$friend_1 = stripslashes($friend_1);
$friend_2 = stripslashes($friend_2);
$friend_3 = stripslashes($friend_3);
$friend_4 = stripslashes($friend_4);
$friend_5 = stripslashes($friend_5);
$friend_6 = stripslashes($friend_6);


hope someone ccan help me...

Kieron
Link to comment
Share on other sites

If you are getting that error then there is a problem with your query:
[code]//retrieves information from database...
$sql = mysql_query("SELECT * FROM tblFriends WHERE myspace_id='$refer_id'");

$data = mysql_fetch_array($sql); -->Line that is causing the problem[/code]
add an or die clause after the query in order to see whats wrong with your query:
[code]//retrieves information from database...
$qry = "SELECT * FROM tblFriends WHERE myspace_id='$refer_id'";
$sql = mysql_query($qry) or die("An internal error has occured!<br />Unable to run the following query:<br /><pre>" . $qry. "</pre><br /><br />" . mysql_error());

$data = mysql_fetch_array($sql);[/code]
Post the error you get now.
Link to comment
Share on other sites

yeah you have to watch out for typos. When ever you are dealing with databases always add the or die caluse to the end of mysql_query so you can easily catch the errors with your queries. Otherwise you'll be sat there for a while wondering what the hells going on. After you finished developing your scripts you should take the or die clauses out. Just for security.
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.