calabiyau Posted January 17, 2007 Share Posted January 17, 2007 Okay i'll give you a little background of what I'm trying to do here. I have a friend who works for a lighting company. They wanted to have an online submission form on their site for people to sign up for an upcoming conference. I told them I could do that pretty easily in php, but soon found out their host does not have php installed. So my solution was I would set up a database on my own space and host the handling script for their form, so the customers would be briefly redirected to my site from the form where I would process it and then send them back to the site, none the wiser that they've left. So I've had this company set up two extra pages, one for successful database insertion and one for failure. In case the database server goes down, I want them to be politely sent to a page that says so instead of getting confusing errors messagesIf I doif (mysql_connect){ header("location: succes.htm"}else{ header("location: failurre.htm"}will this work if the databases are down, or will they get stuck on my page with ugly error messages.If this won't work, I know there is the (or die) option. but can I insert the header command into the or die part to direct them to the correct error page, or does that just take a string message?Thanks. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted January 17, 2007 Share Posted January 17, 2007 mysql_connect() returns a link resource if connected or false on failure so what you could concievably do is[code]<?phpif (mysql_connect(mydatabase) != false) //because it does not return true just a link identifier{ header("location: succes.htm"}else{ header("location: failurre.htm"}?>[/code]this would try and connect to the database, if it was successfull it would go to success.php and failure would go to failure.php, you could then run through the connect script properly Quote Link to comment Share on other sites More sharing options...
trq Posted January 17, 2007 Share Posted January 17, 2007 [quote]if (mysql_connect(mydatabase) != false) //because it does not return true just a link identifier[/quote]Everything except false is considered true in php, so the op's snippet is just as effective. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted January 17, 2007 Share Posted January 17, 2007 [quote]Quoteif (mysql_connect(mydatabase) != false) //because it does not return true just a link identifierEverything except false is considered true in php, so the op's snippet is just as effective.[/quote]thanks for that Thorpe learn something new everyday so if its not explicitly false its TRUE ..but with the Ops post he did not specify a database to check the link to just the mysql_connect command, would you not need it to try and connect to a specific database?? Quote Link to comment Share on other sites More sharing options...
trq Posted January 17, 2007 Share Posted January 17, 2007 All of mysql_connect()'s arguments are optional (you can set the defaults within your php.ini) thhough I think he was just being short in his example. Quote Link to comment Share on other sites More sharing options...
calabiyau Posted January 17, 2007 Author Share Posted January 17, 2007 Yes, I was being short and sloppy I might add with the code I posted. Sorry about that. So as I have it, it should work then? It's just this is the first company i've really done any work for and they are less than happy about being taken off the site so the last thing they want is for their customers to be stuck on someone else's page with all kinds of cannot connect errors. But as I have it, even if the errors are printed to the screen, the else clause will still send them off to the correct page before they would even get to read them right? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.