Rick Emery <[EMAIL PROTECTED]> wrote on 01/14/2002 10:35:37 AM:

> First, if "$submit" is not set, then the "delete" statement will be
> executed.  This will not return an array upon which mysql_fetch_array() 
will
> act.  Therefore $result will not be valid.

I made this change:

        if (!isset($submit)): 
        $sql = "select news_id, bulletin_subject from dbulletins";
        elseif (isset($submit)):
        $sql = "delete from dbulletins where news_id = '$newsid'";
        endif; 

but still get the same error. Shouldn't this fix the problem so now it 
will
return the database list because the submit button is not pushed (on 
returning
to the page)? 

--
Chip

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Monday, January 14, 2002 11:18 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] Why the following error, yet it works anyway
> 
> I have the following short web page to delete dealer bulletins from a
> database. My page lists
> all the bulletins in the database - id and subject. There is a text 
input
> field to enter the bulletin
> id number and hit the delete button, and the bulletin is deleted. It 
works
> except after the submit
> delete I get an error -
> ---------------------------------
> Warning: Supplied argument is not a valid MySQL result resource in
> /usr/local/apache/htdocs/bulletin_delete.php on line 35
> -----------------------------------------
> line 35 is the while statement.
> 
> Here is the complete page -
> -----------------------------------------
> <html>
>   <head>
>     <meta name="generator" content="HTML Tidy, see www.w3.org" />
>     <title>Dealer Bulletins, Simrad, Inc</title>
>   </head>
>   <body>
>     <center><h2>Simrad Dealer Bulletins - Delete Screen</h2>
>     <br /><strong><font color="red">NOTE: This is a permanent and
> irreversible
>                 delete! No second chances here!</font></strong></center>
>  <hr width="75%" noshade="noshade" />
>  <form action="bulletin_delete.php" method ="POST">
>  Enter the bulleting ID Number: <input type="text" name="newsid">
>  <input type="submit" name="submit" value="Delete"></form>
>  <table summary="" border="0" cellpadding="5" align="center" 
width="90%">
>  <?
>    $db = mysql_connect("localhost", "root")
>                  or die ("Can't get the database server");
>     mysql_select_db("bulletins", $db) or die ("Can't get the database");
>     if (isset($submit)):
>     $sql = "delete from dbulletins where news_id = '$newsid'";
>     else:
>     $sql = "select news_id, bulletin_subject from dbulletins";
>     endif;
>     $result = mysql_query($sql);
>      while ($row = mysql_fetch_array($result))
>      {
>      print "<tr>\n<td>Delete entry
> <strong>".$row["news_id"]."</strong>?&nbsp;"
>      .$row["bulletin_subject"]."</td>\n</tr>\n";
>      }
> ?>
> </table>
> <center>
> <a href="bulletin_admin.php">Back</a></center>
> </body>
> </html>
> ----------------------------------------
> --
> Chip Wiegand
> Computer Services
> Simrad, Inc
> www.simrad.com
> [EMAIL PROTECTED]
> 
> "There is no reason anyone would want a computer in their home."
>      --Ken Olson, president, chairman and founder of Digital Equipment
> Corporation, 1977
>  (They why do I have 7? Somebody help me!)
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to