Re: Very stange problem

From: Date: Wed, 05 Jul 2000 00:17:06 +0000
Subject: Re: Very stange problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-4834@lists.php.net to get a copy of this message
> <?php > > $db = mysql_connect("localhost", "root"); > mysql_select_db("gr2",$db); > $result = mysql_query("INSERT INTO tblGrads VALUES (NULL, > '$name','$email','$web','$phone','$dob','$address','$schooling','$experience > ','$interests')",$db); > if($result) > { > print "<P>Worked"; > } > else > { > print "<P>Did not work"; > } > ?> > > It prints "Did not work" to the screen. If I substitute the "$result =..." > line for... > > $result = mysql_query("SELECT * FROM tblGrads",$db); > > ... it prints "Worked". Why will it read, but not write????? It was working > yesterday, and I'm stumped. When you're having problems like this, it's really handy to use mysql_error(). It can be very helpful to modify all of your queries to look something like mysql_query("...") or die(mysql_error()); As soon as you get an error, PHP will stop processing & display the error message. Since you probably don't want the security risk of doing this on a production site, I use a function I wrote: function critical_error_halt($ErrorMessage) { global $HTTP_SESSION_VARS; /* * This function always halts execution and writes $ErrorMessage to the default * error log. If the user is a logged in administrator, it will also display the * real error message instead of a generic failure message. In that case, it also * sends an email to the registered address. * */ error_log($ErrorMessage, 0); if (isset($HTTP_SESSION_VARS["AdminUserID"])) { print "\n\n<PRE>$ErrorMessage\n</PRE>\n\n"; } else { @mail($GLOBALS["DigiCSAdminEmail"], "DigiCS: Request processing halted on critical error", $ErrorMessage); } die("An error occurred while processing your request. The system administrator has been notified."); } mysql_query("...") or critical_error_halt(mysql_error()); This function will display error messages only to logged in administrators. All errors will be logged in any case.

« previous php.general (#4834) next »