0

Need help with this error. Can't see what's wrong.

Error:

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 48

Code:

<?php
$con = mysql_connect("localhost","root",""); //Databse connection
if(!$con)
{
  die ('Could not connect to DB' . mysql_error()); //Error promt
}
mysql_select_db("profound_master", $con); //Selecting the DB
$view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC"); //Selecting the table from the DB

if (!mysql_query ($view, $con))
    {
        die ('Error Sir' . mysql_error()); //Error promt
    }
while ($row = mysql_fetch_array($view))

echo "<table width=\"1000\">";
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>";
?>
0

3 Answers 3

1

You wrote this:

$view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC"); //Selecting the table from the DB
if (!mysql_query ($view, $con))

Notice how you execute the query, assign its result resource to $view, then try to run another query with $view as the SQL? But $view is not SQL, it's a result resource, hence the error.

Just write this:

$view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC");
if (!$view) 
Sign up to request clarification or add additional context in comments.

Comments

0

you can't query result of your query. try this one

$view = mysql_query("SELECT * FROM bulletin ORDER BY pro_no DESC"); //Selecting the table from the DB

if (!$result)

it should do the magic

1 Comment

Thank you very much sir, the error is gone! follow up sir problem sir. I cant see any thing. The table must comes out with the data from DB. :(
0

You actually have two queries. The second query is executed in the if-statement:

if (!mysql_query ($view, $con))

Notice that $view here is of type resource, not of type string. If you want to check that the query executed correctly, just write:

if(!$view)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.