954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

[Help] error in sql select statement

Good day to *.
I having this kind of error when i tried to view all my data in the Database.

Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\pm website\php\bulletin_board\bulletin_board.php on line 51
Error Sir


and here's my code.

<?php
  $con = mysql_connect("localhost","root","");
  if(!$con)
  {
	  die ('Could not connect to DB' . mysql_error());
  }
  mysql_select_db("profound_master", $con);
  $view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC");
  
  if (!mysql_query ($view, $con))
		{
			die ('Error Sir' . mysql_error());
		}
  while ($row = mysql_fetch_array($view));
  
echo "<table>";
echo "<tr id=\"boardLetter\">";
echo "<th width=\"46\">".$row['pro_no']."</th>";
echo "<th width=\"56\">".$row['date']."</th>";
echo "<th width=\"138\">".$row['project']."</th>";
echo "<th width=\"138\">".$row['task']."</th>";
echo "<th>".$row['originated']."</th>";
echo "<th>".$row['incharge']."</th>";
echo "<th>".$row['deadline']."</th>";
echo "<th width=\"139\">".$row['status']."</th>";
echo "<th width=\"151\">".$row['comment']."</th>";
echo "<th>".$row['din']."</th>";
echo "</tr>";
echo "</table>";
?>


Please help me to solve my problem.

God bless to *.

pakunoda
Newbie Poster
17 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

You are doing this wrong.

if (!mysql_query ($view, $con))
		{
			die ('Error Sir' . mysql_error());
		}


mysql_query() function's first argument should be a string(a SQL query).

Once you have queried the database using $view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC"); , you check the return value of mysql_query() to see if it executed successfully. It returns false on error. Hence
to check

if (!$view) {
    // error
}
vishesh
Nearly a Posting Virtuoso
1,381 posts since Oct 2006
Reputation Points: 85
Solved Threads: 42
 

Yes vishesh is correct. Try with vishesh suggestion or Replace your line from 8 to 13

$view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC");
 
if (!mysql_query ($view, $con))
{
die ('Error Sir' . mysql_error());
}


with

$view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC") or die ('Error Sir' . mysql_error());
Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: