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)

New User

joined:Jan 5, 2013
votes: 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)

Senior Member

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

joined:Aug 7, 2003
votes: 0

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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 15, 2004
votes: 0

... 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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2003
votes: 5

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)

Junior Member

5+ Year Member

joined:Nov 16, 2008
posts: 136
votes: 0

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