Hello,
I’m currently creating a PHP site that lets people view info from a database, and lets admins edit the info, or add.
I got the users and login system working ok, but I’ve run into a weird problem:
I have a file called view.php. If I click on ‘networks’ it will load view.php?mode=networks. This is working fine. If I click on shows it will load view.php?mode=shows.
This is view.php:
<?php
session_start();
include 'header.php';
include 'menu.php';
$mode = $_GET['mode'];
if($mode == 'networks')
{
connect();
$data = mysql_query("SELECT * FROM network");
mysql_close();
echo '<h1>Networks</h1><p>This is a listing of all Networks in our database.</p><table class="datatable"><tr><th>Network</th><th>Website</th></tr>';
while($nwdata = mysql_fetch_array($data))
{
echo '<tr><td>' . $nwdata[network_name] . '</td><td>' . $nwdata[network_site] . '</td></tr>';
}
echo '</table>';
if($_SESSION['level'] == 3)
{
echo '<a href="add.php?mode=network">Add new</a>';
}
}
else if($mode == 'shows')
{
connect();
$shows = mysql_query("SELECT * FROM show");
echo '<h1>Shows</h1><p>This is a listing of all Shows in our database.</p><table class="datatable"><tr><th>Show</th><th>Network</th></tr>';
while($show = mysql_fetch_array($shows))
{
//$nw = mysql_query("SELECT network_name FROM network WHERE network_id = '$show[network_id]'");
echo '<tr><td>' . $show[show_name] . '</td><td>' . $show[show_id] . '</td></tr>';
}
echo '</table>';
mysql_close();
if($_SESSION['level'] == 3)
{
echo '<a href="add.php?mode=show">Add new</a>';
}
}
include 'footer.php';
?>
The problem is that I get this error when I go to view.php?mode=shows:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in x:\xxx\xxx\xxx\view.php on line 31
Line 31 is this one:
while($show = mysql_fetch_array($shows))
networks work fine, but shows cause a problem. I have no idea why, and I’ve tried to find the answer myself, no luck so far. Any ideas?