Jump to content

Stopping mysql errors?


Cory94bailly

Recommended Posts

Well I am making an install.php for if I ever make a script worth giving out...

 

So far, I have the basic mysql stuff where the site admin puts in their mysql details and the info is processed...

 

But if the admin enters something wrong, you will get the usual mysql errors..

 

So, I want to know how to make it say my own errors...

 

Like maybe red text saying "That DB doesn't exist!"

 

Any help will help (besides google....)

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/105197-stopping-mysql-errors/
Share on other sites

This should work.

 

When you execute your queries:

 

$var = mysql_query($sql) or die("The query could not be executed");

 

So you put some text in the brackets following "or die" and it should display that text instead of the standard mysql_error()

 

How can I customize it for each error?

Define what "each error" means.

 

You run a connect routine which either connects or it doesn't.  You run a db select routine which either connects or doesn't.  Then you execute sql commands which either are commited or they are not.  Not too many specifics there to customize.

Well like this:

 

Invalid MySql Path: Sorry, that Mysql path is Invalid!

Invalid MySql Database: Sorry, that Mysql database is Invalid!

Invalid MySql Username: Sorry, that Mysql username is Invalid!

Invalid MySql Password: Sorry, that Mysql password is Invalid!

 

 

And I want it only so if they get 1 or 2 wrong, it will only show those 1 or 2.. Not them all!

 

 

change the die message?

 

Obviously =/

 

 

post the code please

 

Code..?

mysql_select_db($db) or die ("Sorry, that Mysql database is Invalid!");

 

Just like that, change the DIE message to whatever you want it to be.

 

Ok I get that much but how would I do it if I had the code like this:

 

    mysql_connect("$sqlpath", "$sqluser", "$sqlpass") or die(mysql_error());
    mysql_select_db("$sqldb") or die(mysql_error());

 

How would I make an error only come up for each wrong field?

 

Like say they got the path and DB wrong, I don't want it saying "Sorry, that password is incorrect!"...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.