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
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()

Link to comment
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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..?

Link to comment
Share on other sites

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!"...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.