February 06 2012 04:03:22
Navigation
Last Seen Users
CrystalOnline
PodrsOnline
ThomasOnline
skpacmanOnline
hilgendorf< 5 mins
linux121< 5 mins
h1rikh00:11:43
djp00:38:07
adamos4200:44:18
Paulen00:46:14

Members: 24,063
Newest: baysersery
Things to Do
Downloads v7
Currently popular Downloads

FusionBoard 4 6150
Video Gallery 4372
Video Infusion 3849
Photoalbum Mass U... 3427
Professional Down... 3321
Avatar Studio 3250
XHTML mod for mod... 3014
Button panel 2649
60 Animated smileys 2464
VArcade 2.1 2443

Latest Downloads


XHTML mod for modern... 3014
The Movie House v2.0 20
table tool 12
RedCar Theme 18
Server Theme 13
DigiDot Theme 15
Cyber Theme 10
Userfield: Twitter 12
TMH User Info Panel 18
ajaxuser_info_panel ... 69

Latest 100
Downloads v6
Currently popular Downloads

Banner System v2.0.4 2244
Video Gallery 1529
Extreme Theme Editor 1218
Fuzed Shoutbox 1043
Seoname.php 986
Icon Package 2.0 860
Extended Profile ... 764
News.php 692
Tabbed welcome panel 642
EXTboard 583

Latest Downloads


Banner System v2.0.4 2244
Last comments 100
Language switcher panel 303
Admin Submission Panel 129
Admin private messag... 244
Google Sitemap Fast 139
ExtBoard 1.2 430
EXTboard 583
v6.01.18 - v6.01.19 72
v6.01.19 FULL 220

Latest 100
Latest Articles
Patch Re-captcha PHP...
A tour through the n...
Protect your Fusion ...
Change your database...
Admin Control Panel ...
How to Secure Your I...
Show Content by Defa...
v7 | Add social book...
v7 | Custom MySQL er...
How To: A PM after r...
v7 | SEO friendly UR...
v7 | SEO friendly UR...
Comments Advanced Vi...
Auto-redirect to the...
A tour through PHP-F...

View all articles
v7 | Custom MySQL error messages
This guide will show you how to make custom error messages in PHP-Fusion, to let the user know what's wrong (instead of the MySQL error-codes)

This is my first How-To, so I'm not sure if I'm very clear.

This is especially handy if you NEED a certain image to display or just want a more user friendly error message.

This How-To was written based on Version 7 codes, any other version of PHP-Fusion may not work.


1: Make a backup of maincore.php, name it whatever you want. you can use this incase anything should go wrong.

2: open the original maincore.php (in notepad, i recommend notepad++ though)

3: search for line 18: if (eregi("maincore.php", $_SERVER['PHP_SELF'])) { die(); }

4: under that add $custerr="some nice error code here";
(line 19)

it should now look like this

if (eregi("maincore.php", $_SERVER['PHP_SELF'])) { die(); }
$custerr="some nice error code here";

5: go to line 106, the following code will start from there

// MySQL database functions
function dbquery($query) {
$result = @mysql_query($query);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}

function dbcount($field, $table, $conditions = "") {
$cond = ($conditions ? " WHERE ".$conditions : "");
$result = @mysql_query("SELECT Count".$field." FROM ".$table.$cond);
if (!$result) {
echo mysql_error();
return false;
} else {
$rows = mysql_result($result, 0);
return $rows;
}
}

function dbresult($query, $row) {
$result = @mysql_result($query, $row);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}

function dbrows($query) {
$result = @mysql_num_rows($query);
return $result;
}

function dbarray($query) {
$result = @mysql_fetch_assoc($query);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}

function dbarraynum($query) {
$result = @mysql_fetch_row($query);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}

function dbconnect($db_host, $db_user, $db_pass, $db_name) {
$db_connect = @mysql_connect($db_host, $db_user, $db_pass);
$db_select = @mysql_select_db($db_name);
if (!$db_connect) {
die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>Unable to establish connection to MySQL</b><br />".mysql_errno()." : ".mysql_error()."</div>");
} elseif (!$db_select) {
die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>Unable to select MySQL database</b><br />".mysql_errno()." : ".mysql_error()."</div>");
}
}

6: replace above with:

// MySQL database functions
function dbquery($query) {
$result = @mysql_query($query);
if (!$result) {
echo $custerr;
return false;
} else {
return $result;
}
}

function dbcount($field, $table, $conditions = "") {
$cond = ($conditions ? " WHERE ".$conditions : "");
$result = @mysql_query("SELECT Count".$field." FROM ".$table.$cond);
if (!$result) {
echo $custerr;
return false;
} else {
$rows = mysql_result($result, 0);
return $rows;
}
}

function dbresult($query, $row) {
$result = @mysql_result($query, $row);
if (!$result) {
echo $custerr;
return false;
} else {
return $result;
}
}

function dbrows($query) {
$result = @mysql_num_rows($query);
return $result;
}

function dbarray($query) {
$result = @mysql_fetch_assoc($query);
if (!$result) {
echo $custerr;
return false;
} else {
return $result;
}
}

function dbarraynum($query) {
$result = @mysql_fetch_row($query);
if (!$result) {
echo $custerr;
return false;
} else {
return $result;
}
}

function dbconnect($db_host, $db_user, $db_pass, $db_name) {
$db_connect = @mysql_connect($db_host, $db_user, $db_pass);
$db_select = @mysql_select_db($db_name);
if (!$db_connect) {
die("$custerr");
} elseif (!$db_select) {
die("$custerr");
}
}

7: Save file and re-upload
8: If anything went wrong, restore from the backup you made in step 1.

Hint:
you can also make multiple error message for each instance, for example:

if (eregi("maincore.php", $_SERVER['PHP_SELF'])) { die(); }
$custerr="query error";
$custerr2="dbcount function error";


// MySQL database functions
function dbquery($query) {
$result = @mysql_query($query);
if (!$result) {
echo $custerr;
return false;
} else {
return $result;
}
}

function dbcount($field, $table, $conditions = "") {
$cond = ($conditions ? " WHERE ".$conditions : "");
$result = @mysql_query("SELECT Count".$field." FROM ".$table.$cond);
if (!$result) {
echo $custerr2;
return false;
} else {
$rows = mysql_result($result, 0);
return $rows;
}
// rest of mysql functions here


etc :)

Hope you like it, it's a bit simple, but useful :)

Written by Joey van Hummel
Comments
#1alternator on October 10 2009 19:06:06
alternator
nice code. this is what i need. sometime web hosting limiting their sql connection and an error always come up with non-user friendly message.
Post Comment
Please Login to Post a Comment.
Ratings
Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Our Coders
Smokeman
Elyn @ MrRusty
Diemux
Netrix
Donate
Shoutbox
You must login to post a message.

02/02/2012 18:10
Hi I'm looking for some Polish script that will show the panel of selected members of Facebook have heard about something like that?

31/01/2012 16:18
been using pf for fair time.. love it .keep up the awesome work guys ..

31/01/2012 07:11
Hey Netrix

28/01/2012 00:52
BOT

27/01/2012 10:12
I miss you guys! Yep!

27/01/2012 09:37
It's ok no need to say you're sorry - we can discuss it of course. And no - my feathers was not getting ruffled. No!

27/01/2012 08:58
I dont have a problem donating , and I was not talking any way smokeman....it was a question because it seems dead around here anymore. That was all, sorry you got your feathers ruffled

27/01/2012 05:04
Because you don't get your free help/support as quick as you want there's no need to talk the way you do - _Mighty_

27/01/2012 05:03
Dev. ain't stopped. For under 1 months ago Diemux added 15 new downloads to the DL DB: http://www.phpfus.
..owstart=20

26/01/2012 17:20
Who said that development stops?

Advertiser
One-click Translation
Translate This Site

Online Stats
Guests online: 8
Members online:
Crystal, Thomas, skpacman, Podrs

registered members: 24063
newest member: baysersery

user today: 4889
user online: 12
Max. onlinerecord: 83
Max. per day: 32490
user yesterday: 10832
user month: 46161
Entire users: 2974308

last 24h:
























In memoriam

Nick Jones
1973-2011
Render time: 2.65 seconds - 93 Queries 16,621,969 unique visits