0

Hello Every one, im in a need for some help
i have the following issue :
--- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\00000\html\index.php on line 10
this is what the code looks like
Can some one please assist me on what is wrong with it thanks much.

$sql = mysql_query("SELECT * FROM forum_posts WHERE type='a' ORDER BY date_time DESC LIMIT 0, 30"); 
$topicsBody = "";

while($row = mysql_fetch_array($sql)){
	$id = $row["id"];
	$post_author = $row["post_author"];
	$post_author_id = $row["post_author_id"];
	$thread_author = $row["thread_author"];
	$original_thread_id = $row["original_thread_id"];
	$date_time = $row["date_time"];
    $date_time = strftime("%a %b %d, %Y %I:%M:%S %p", strtotime($date_time));
	$type = $row["type"];
	$view_count = $row["view_count"]; 
	$category = $row["category"];
	$category = substr('' . $category . '', 0, 15);  
	$cat_ref_num = $row["cat_ref_num"];	
	$title = stripslashes($row["title"]);
	$title = htmlentities($title);
	$title = substr('' . $title . '', 0, 48);

Edited by nav33n: Please use [code] tags to wrap your code for easy readability.

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by venkat0904
0

You have not passed conection parameter. change you code as given below.

[b]  $conn = mysql_connect("servername","username","password");[/b]

$sql = mysql_query("SELECT * FROM forum_posts WHERE type='a' ORDER BY date_time DESC LIMIT 0, 30"[b],$conn[/b]);
0

You have not passed conection parameter. change you code as given below.

[b]  $conn = mysql_connect("servername","username","password");[/b]

$sql = mysql_query("SELECT * FROM forum_posts WHERE type='a' ORDER BY date_time DESC LIMIT 0, 30"[b],$conn[/b]);

Thanks for the help where would i plugging in this in which script?
$conn = mysql_connect("servername","username","password");

0

add my lines of code before $topicsBody = "";

Hey I did as you told me, I feel i am getting somewhere,and i do apperciate it. Now i got this error when i tried.
Access denied for user 'me'@'11.11.11.1' (using password: YES) in D:\Hosting

You think its my account settings?

0

Thanks for the help where would i plugging in this in which script?
$conn = mysql_connect("servername","username","password");

if you are doing inyour localhost then write bellow

<?
$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db=mysql_select_db('databasename',$con);
?>
0

Hello Every one, im in a need for some help
i have the following issue :
--- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\00000\html\index.php on line 10
this is what the code looks like
Can some one please assist me on what is wrong with it thanks much.

$sql = mysql_query("SELECT * FROM forum_posts WHERE type='a' ORDER BY date_time DESC LIMIT 0, 30"); 
$topicsBody = "";

while($row = mysql_fetch_array($sql)){
	$id = $row["id"];
	$post_author = $row["post_author"];
	$post_author_id = $row["post_author_id"];
	$thread_author = $row["thread_author"];
	$original_thread_id = $row["original_thread_id"];
	$date_time = $row["date_time"];
    $date_time = strftime("%a %b %d, %Y %I:%M:%S %p", strtotime($date_time));
	$type = $row["type"];
	$view_count = $row["view_count"]; 
	$category = $row["category"];
	$category = substr('' . $category . '', 0, 15);  
	$cat_ref_num = $row["cat_ref_num"];	
	$title = stripslashes($row["title"]);
	$title = htmlentities($title);
	$title = substr('' . $title . '', 0, 48);

typically, for any operation in database the sequence goes like this--
1) create a connection (can use mysql_connect())
2) select a db (use mysql_select_db())
3) perform ur queries (through mysql_query())

and for the error.. make sure ur credentials are correct and u are using correct servername. Try logging in with same credentials in phpmyadmin..
Hope this helps.. Cheers!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.