Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199807

Re: [PHP3] Why am i getting a warning From: Richard Lynch (lynch <email protected>)
Date: 07/31/98

At 12:11 AM 7/30/98, npafitis wrote:

>Warning: -1 is not a MySQL link index in
>/usr/local/www2/data/php3-files/insert.phtml on line 102
>
>Where line 102 is mysql_close();

You've probably got something like this:

if (... data checks out okay ...){
  ... insert data ...
  ... display inserted data ...
}
mysql_close();

Of course, there's a bizillion lines of code in that middle part, so you
don't realize what you've done.

So the only time the mysql connection is opened is when the data is okay,
but you are *ALWAYS* closing the connection.

Move your mysql_close(); into the if statement.

For future reference: It is not a bad idea when writing a script to do
something like this:

<?php
  $valid = 1;
  echo("Check data and set valid to 0 if it's bad.<BR>\n");
  if ($valid){
    echo("Insert data.<BR>\n");
    echo("Display data just inserted.<BR>\n");
    echo("Close connection.<BR>\n");
  }
?>

Then, try it to see what happens when you set $valid = 0;

*THEN*, put in the stuff to get the data into your form, but don't actually
do the inserts. Just add the variables to the echo strings.

*FINALLY*, when you know your logic is correct, add the mysql_xxx to do the
actual work.

The point being that it's a lot easier to debug your logic, especially if
it's complex logic, when you don't have 100 lines of code between your if
and its closing bracket.

Take a few minutes to plan your script, and build its complexity in from a
top-down standpoint. IE Get the major logic/actions organized and debugged
*FIRST*, then add in the data I/O to the web, and finally the data I/O to
the database. The extra half hour or hour you spend doing this at the
beginning will save you 10 hours of debugging time later.

--
--
-- "TANSTAAFL" Rich lynch <email protected>

-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3