So I came across a problem when I was making a form that allows a user to connect to their mySQL database. Here's the code:
if ($_POST['submit']) {
$sqlhost=$_POST['sqlhost'];
$sqluser=$_POST['sqluser'];
$sqlpass=$_POST['sqlpass'];
$errorstring="";
//error checking
if ($sqlhost=="") {
$errorstring.="Host cannot be left empty!<br>";
}
if ($sqluser=="") {
$errorstring.="User cannot be left empty!<br>";
}
//if their are errors display the error message
if ($errorstring<>"") {
echo "<center id=\"error\">$errorstring</center><p>";
}
else
//no errors
mysql_connect("$sqlhost","$sqluser","$sqlpass") or die ("Unable to connect!");
Alright, that looks all good and dandy? It is. The only problem is if the user types in a database that we cannot connect to, it displays an error:
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'rssr' (1) in /Applications/XAMPP/xamppfiles/htdocs/install.php on line 40
Unable to connect!
Thing is, I don't want it to display that error. I only want it to display my error, which is "Unable to connect", and not the computer generated error.
Hope you understand what the hell I'm talking about :-\
- Miles