"David Jackson" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> All --
> It appears that the problem was a table design problems,
> my primary index wasn't set to auto-increment? So I was trying to
> insert records with duplicate keys !!
> This of course leads to another question, how do I return SQL error
messages
> to the browser?
>
> Thanks,
> David
>

Out of habit, I abstract all of the MySQL functions to handle this. My
current setup for http://hosting.venura.net/ (still under construction).
outputs error messages like this:

function sqlQuery($query, $secure = 0) {
 $result = mysql_query($query);
 if(!$result) {
  if($secure) {
   $query = '*** hidden ***';
  }
  else {
    /* This is just an oddity from how I construct some queries, primarily
INSERTs. If all of your queries are on a single line of text with no
leading/trailing whitespace or you don't care about appearance, you can
delete this section of the code */

   $query = explode("\n", $query);
   foreach($query as $line => $text) {
    $query[$line] = trim($text);
   }
   $query = implode("\n", $query);
  }

  die('<h1>Oops...</h1><p><b>Sorry, but something seems to have gone
terribly wrong...</b></p>
<pre>
MySQL Error Number:      ' . htmlspecialchars(mysql_errno()) . '
MySQL Error Description: ' . htmlspecialchars(mysql_error()) . '

Query Text:
' . htmlspecialchars($query) . '

</pre>
<p>(Yes, you probably have found a bug.)</p>
  ');
 } else return ($result);
}


This will dump the query, error number and error description whenever a SQL
query fails. You can set the optional second parameter ($secure) to true if
your query involves anything that you don't want the end-user to see, such
as updating a password or something like that.

disclaimer: I didn't check to see what database engine you're using. If
you're using MySQL, this should work, otherwise use something similiar.






-- 
PHP General 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