On Mon, 15 Dec 2003 17:44:56 -0500, "Ed Wurster" <ea_wurster@comcast.net>
wrote:
[color=blue]
>I'm in the early stages of the tutorial, and find a need to error check, to
>see if I am connected to the database and so on.
>
>For instance I'm getting this error:
>
>Warning: mysql_result(): supplied argument is not a valid MySQL result
>resource in /home/(rest of path omitted) on line 9
>firstN:
>
>I know from reading through messages in this group that I shopuld include
>some error checking in the example.
>
>For instance, I've modified the tutorial to something more relevant for me:
>
><?php
>$db = mysql_connect("localhost", "user", "password");[/color]
$db = mysql_connect("localhost", "user", "password")
or die ("Connect failed: " . mysql_error());
[color=blue]
>mysql_select_db("database_contacts",$db);[/color]
mysql_select_db("database_contacts",$db);
or die ("Database selection failed: " . mysql_error());
[color=blue]
>$result = mysql_query("SELECT * FROM peeps", $db);[/color]
$result = mysql_query("SELECT * FROM peeps", $db);
or die ("Query failed: " . mysql_error());
[color=blue]
>printf("firstN: %s<br>\n", mysql_result($result,0,"firstN"));[/color]
Never proceed to using a resource handle before checking you actually _have_ a
resource handle, instead of 'false' returned by an error; see above.
The error handling above is OK for debugging but you should handle it more
gracefully for production code.
--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (
http://www.andyh.co.uk)
Space: disk usage analysis tool (
http://www.andyhsoftware.co.uk/space)