I'm trying to make a PHP script that automaticly makes a link on the side
menu to the id page that was just made, under certain catagories. But I
edited my code to cleen up soem errors and all of a sudden 3 errors came up,
and I haven't been able to fix them! They are:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in C:\Inetpub\wwwroot\main\menu.php on line 29
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in C:\Inetpub\wwwroot\main\menu.php on line 41
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in C:\Inetpub\wwwroot\main\cat.php on line 39

The code for the menu and cat *.php files are below:

menu.php:
<HTML>

<HEAD>

  <link href="/css/base.css" rel="STYLESHEET" type="text/css">

</HEAD>

<BODY>

  <TABLE width=100% cellPadding=0 cellSpacing=0>

    <TR>

      <TD width=150 vAlign=top>

        <?php

          $register_globals;

          $db = mysql_connect("localhost","root");

          mysql_select_db("common",$db);

          $result = mysql_query("SELECT * FROM main",$db);

          echo "<center>Main</center><br>";

          while ($row1 = mysql_fetch_array($result)) {

            if ($row1["cat"] == 1) {

              printf("<a href=\"pages.php?cat=1&id=%s\">%s</a><br>",
$row1["id"], $row1["title"]);

            }

          }

          echo "<center>Misc.</center><br>";

          while ($row1 = mysql_fetch_array($result)) {

            if ($row1["cat"] == 2) {

              printf("<a href=\"pages.php?cat=2&id=%s\">%s</a><br>",
$row1["id"], $row1["title"]);

            }

          }

        ?>

      </TD>

      <TD>

cat.php:

<?php

  if ($submit) {

    if ($id) {

      $sql = "UPDATE main SET content='$content', title='$title' cat='$cat'
WHERE id=$id";

    } else {

      $sql = "INSERT INTO main (content,title,cat) VALUES
('$content','$title','$cat')";

    }

    $result = mysql_query($sql);

    echo "Record updated/edited!<p>Return to <A
href=\"pages.php?cat=$cat&id=$id\">Index</a>.";

  } elseif ($delete == areyousure) {

    $sql = "SELECT * FROM main WHERE id=$id";

    $result = mysql_query($sql);

    echo "Are you sure you want to delete $title?<p><a
href=\"$PHP_SELF?cat=$cat&id=$id&delete=true\">Yes</a> | <a
href=\"$PHP_SELF\">No</a>";

  } elseif ($delete == true) {

    $sql = "DELETE FROM main WHERE id=$id";

    $result = mysql_query($sql);

    echo "$title Record deleted!<p><a
href=\"$PHP_SELF?cat=$cat&id=$cat\">Return</a>";

  } else {

    $result = mysql_query("SELECT * FROM main",$db);

    while ($row = mysql_fetch_array($result)) {

      if ($id == $row["id"] && $cat == $row["cat"]) {

        printf("<center><font size=5>%s</font></center><br><br>",
$row["title"]);

        printf("%s<br><br>", $row["content"]);

        printf("<a
href=\"$PHP_SELF?cat=$cat&id=%s&delete=areyousure\">(DELETE)</a><br>",
$row["id"]);

        printf("<a
href=\"$PHP_SELF?cat=$cat&id=%s&edit_add=$cat\">(EDIT)</a><br>",
$row["id"]);

      }

    }

    echo "<P><a href=\"$PHP_SELF?cat=$cat&edit_add=$cat\">ADD A
RECORD</a><P>";

  }

?>

<?php

  if ($edit_add) {

?>

  <form method="post" action="pages.php?cat=<?php echo $cat ?>">

  <?php

    if ($id) {

      $sql = "SELECT * FROM main WHERE id=$id";

      $result = mysql_query($sql);

      $row = mysql_fetch_array($result);

      $id = $row["id"];

      $title = $row["title"];

      $cat = $row["cat"];

      $content = $row["content"];

    ?>

    <input type=hidden name="id" value="<?php echo $id ?>">

  <?php

    }

  ?>

  <TABLE cellPadding="0" cellSpacing="0" border="0">

    <TR>

      <TD>Title:</TD>

      <TD><input type="Text" name="title" value="<?php echo $title ?>"></TD>

      <TD rowSpan="2" vAlign="Top">

        <TABLE border="0" cellPadding="0" cellSpacing="0">
          <?php

            $result = mysql_query("SELECT * FROM cat",$db);

            while ($cat = mysql_fetch_array($result)) {

              printf("<TR><TD>%s</TD><TD><input type=\"radio\" name=\"cat\"
value=\"%s\"></TD></TR>", $cat["name"], $cat["id"]);

            }

          ?></TD></TR></TABLE></TD></TR>

    <TR>

      <TD>Message:</TD>

      <TD rowSpan="3"><textarea name="content" rows="7" cols="40"
wrap="virtual"><?php echo $content ?></TEXTAREA></TD></TR></TABLE>

  <input type="Submit" name="submit" value="Enter information">

  </form>

<?php

  }

?>


Anny help would be highly appreciated!
Thank You for your time.

-Ben

Reply via email to