Click to See Complete Forum and Search --> : Suppressing PHP Warnings


Josh
10-17-2003, 02:50 PM
Any ideas on how I can rewrite this so when the script fails, the only text on the screen will be my own custom warning?<?php
$mysql_server = "";
$mysql_user = "";
$mysql_password ="";

$link = mysql_connect("$mysql_server", "$mysql_user", "$mysql_password");

if ($link) {
print ("<p>Connected successfully</p>");
} else {
print ("<p>Could not connect</p>");
}

mysql_close($link);
?>Here's an example of what the page looks like when the script fails. (http://vintagecloning.host.sk/test)

PunkSktBrdr01
10-17-2003, 03:16 PM
The page you linked to said "Forbidden
You don't have permission to access /test on this server." Was that the error message? Anyway, to block error messages, put "@" in front of the function, like:

@mysql_connect(...);


You can also use the die() function to create an error message, like:


@mysql_connect(...) or die("Sorry, there has been an error: " . mysql_error());


Hope that's what you're looking for!

Josh
10-17-2003, 04:28 PM
Yes it worked like a charm. Here's the modified code...<?php
$mysql_server = "";
$mysql_user = "";
$mysql_password ="";

$link = @mysql_connect("$mysql_server", "$mysql_user", "$mysql_password");

if ($link) {
print ("<p>Connected successfully</p>");
} else {
print ("<p>Could not connect</p>");
die();
}

mysql_close($link);
?>I can't figure out why the page would say "Forbidden.." when I click the link, it takes me right to the page. Oh well... thanks again though.

piersk
10-21-2003, 11:32 AM
Looks to me like an Apache page that only allows access from certain IPs.