Where did I go wrong? I’m getting the following error message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in (…)/dbtest2.php on line 24
Line 24 is this: while($row = mysql_fetch_array($rs, MYSQL_ASSOC))
dbtest2.php:
[code=php]
<?php
(my databse connection details go here…)
$sql = “SELECT id, test1, test2 FROM testtabell WHERE test1={$_GET[‘test1’]}”;
$rs = mysql_query($sql);
echo “<table><tr>”;
echo “<th>id</th>”;
echo “<th>test1</th>”;
echo “<th>test2</th></tr>”;
while($row = mysql_fetch_array($rs, MYSQL_ASSOC))
{
echo “<tr><td>{$row[‘id’]}</td>”;
echo “<td>{$row[‘test1’]}</td>”;
echo “<td>{$row[‘test2’]}</td></tr>”;
}
mysql_close($conn);
echo “</table>”;
?>
The above page get the querystring from the links created in the following page, dbtest.php (this page seems to be working just fine, by the way — only the above-mentioned page, dbtest2.php, throws an error):
[code=php]
<?php
(again, my databse connection details go here…)
$sql = ‘SELECT id, test1, test2 FROM testtabell’;
$rs = mysql_query($sql);
echo “<table><tr>”;
echo “<th>id</th>”;
echo “<th>test1</th>”;
echo “<th>test2</th></tr>”;
while($row = mysql_fetch_array($rs, MYSQL_ASSOC))
{
echo “<tr><td>{$row[‘id’]}</a></td>”;
echo “<td><a href=”dbtest2.php?test1={$row[‘test1’]}”>{$row[‘test1’]}</a></td>”;
echo “<td>{$row[‘test2’]}</td></tr>”;
}
mysql_close($conn);
echo “</table>”;
?>
Now, it works as it should if I use the ID part as a querystring but it doesn’t work with test1. So, once again: where did I go wrong?