Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Warning: mysql fetch array() expects parameter 1 to be resource.



10:40 am on Jan 5, 2013 (gmt 0)

hey guys, i'm a beginner in php.
i'm so confused.
i know my query is correct but this error always appear:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean...

here's the code:


echo "<form action='catps.php' method='get'>";

echo "<h3><center>Choose Object Class / Account Codes</center></h3>";
$result = mysql_query("SELECT * FROM `account_codes`");
echo "<table><tr><th width='150px'>Object Class</th><th align='center' width='450px'>Name</th><th align='center' width='30px'>Choose</th></tr>";

echo "<td align='center'>".$row['Account_Code_Number']."</td>";
echo "<td>".$row['Title']."</td>";
echo "<input type='hidden' value=".$row['Account_Code_Number']." name='acctcdnum' />";
echo "<input type='hidden' value='".$row['Title']."' name='accttitle' />";
echo "<td><input type='checkbox' name='check[".$i."]' float='right' value='".$row['Account_Code_Number']."'/></td>";
echo "</tr>";
echo "</table>";
echo "<br/><br/><center><input type='submit' name='sub' value='SUBMIT' float='right'/></center>";
echo "<br/><br/><br/>";

echo "</form>";

$sql = mysql_query("insert into `account_codes_classified`(`Account_Code_Number`,`Category_Number`) values (`".$check[$i]."`,100)");
echo "Successful";}

thanks in advance.


3:58 am on Jan 6, 2013 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

If you're a beginner, then do yourself a BIG favour:
- forget about the obsolete mysql interface
- switch to the mysqli (note the i) interface and use prepared statements

That way you would have quite a big reduction in security bugs. (BTW: if you get this to work: it's begging for getting hacked with sql injection)


5:38 am on Jan 6, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

... wherever you have got this ` change to this ' and that code should run fine (did you notice the difference).

Of course, security is a different issue.


8:04 am on Jan 6, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Unless you deleted some code from the original, I'd say your call to mysql_query failed because you haven't opened a connection to the database.


1:47 pm on Jan 8, 2013 (gmt 0)

5+ Year Member

your best solution : [php.net...]
mysql_ everything is deprecated

Featured Threads

Hot Threads This Week

Hot Threads This Month