Help! im having trouble error handling mysqli_connect() with posted passwords.
Help! im having trouble error handling mysqli_connect() with posted passwords.
am 14.02.2006 00:38:43 von Ninja_Monkey
hi im trying to write myself a simple database management system. and I have
noticed that whenever i use a connect command like this:
$connection = mysqli_connect($_POST['host'], $_POST['user'],
$_POST['pass']);
if all three parts are supplied it goes ok and returns an Object which i can
check after with is_object($connection).
However if there is the $_POST['pass'] empty and it is required. the error
it generates automaticly prints the error where the mysqli_connect() was
called even if i add 'or die()' at the end.
i have found that the type this error returns is boolean but i cant seem to
get the error to stop printing automaticy as its called?
i have tried putting scripts in strait after like if
(mysqli_connect_errno()) {} ect. and the error still prints at the call.
can anyone help?
Re: Help! im having trouble error handling mysqli_connect() withposted passwords.
am 14.02.2006 01:24:07 von Shion
Ninja_Monkey wrote:
> hi im trying to write myself a simple database management system. and I have
> noticed that whenever i use a connect command like this:
> $connection = mysqli_connect($_POST['host'], $_POST['user'],
> $_POST['pass']);
I think you should test the variables first to see that you have at least host
and user.
/* we prevent error message to be typed out with the @ */
if($connection = @mysqli_connect($_POST['host'], $_POST['user'],$_POST['pass'])) {
/* connection went okey */
} else {
/* connection failed */
}
> if all three parts are supplied it goes ok and returns an Object which i can
> check after with is_object($connection).
> However if there is the $_POST['pass'] empty and it is required. the error
> it generates automaticly prints the error where the mysqli_connect() was
> called even if i add 'or die()' at the end.
die() don't stop error message output, it just kills the script.
//Aho
Re: Help! im having trouble error handling mysqli_connect() with posted passwords.
am 14.02.2006 11:28:53 von Ninja_Monkey
thanks a lot. il give that a try. whats the @ sign for? ive never seen that
method used before?
"J.O. Aho" wrote in message
news:45cm97F5tkm7U1@individual.net...
> Ninja_Monkey wrote:
> > hi im trying to write myself a simple database management system. and I
have
> > noticed that whenever i use a connect command like this:
> > $connection = mysqli_connect($_POST['host'], $_POST['user'],
> > $_POST['pass']);
>
> I think you should test the variables first to see that you have at least
host
> and user.
>
> /* we prevent error message to be typed out with the @ */
> if($connection = @mysqli_connect($_POST['host'],
$_POST['user'],$_POST['pass'])) {
>
> /* connection went okey */
>
> } else {
> /* connection failed */
> }
>
> > if all three parts are supplied it goes ok and returns an Object which i
can
> > check after with is_object($connection).
> > However if there is the $_POST['pass'] empty and it is required. the
error
> > it generates automaticly prints the error where the mysqli_connect() was
> > called even if i add 'or die()' at the end.
>
> die() don't stop error message output, it just kills the script.
>
>
> //Aho
Re: Help! im having trouble error handling mysqli_connect() withposted passwords.
am 14.02.2006 11:34:21 von Shion
Ninja_Monkey wrote:
> thanks a lot. il give that a try. whats the @ sign for? ive never seen that
> method used before?
It's for suppressing error message outputs from functions, just place it
infront of a function which you don't want to output error messages directly
to the webpage, but do that with care as it makes it more difficult to hunt bugs.
//Aho