May 17 2012 12:04:27
Navigation
Last Seen Users
J_K_NIELSEN00:41:00
volt12301:09:14
darans01:09:31
Acert01:43:23
michi02:06:53
LukeWarm02:10:55
Dave9202:48:59
KasteR02:52:49
colber03:10:27
rubberdark04:17:28

Members: 25,040
Newest: Dave92
Downloads v7
Currently popular Downloads

FusionBoard 4 6351
Video Gallery 4524
Video Infusion 4019
Photoalbum Mass U... 3499
Professional Down... 3403
Avatar Studio 3338
XHTML mod for mod... 3186
Button panel 2703
60 Animated smileys 2610
VArcade 2.1 2532

Latest Downloads


Code Snippets v1.10 8
Video Infusion Pro 84
Who Is Where 16
Facebook Login/Register 62
Yolks Smiley Pack 56
SWTOR Recruiting Panel 25
NeoBlog Theme 28
Code Snippets 9
FAQ Panel 15
Download Plus Panel 32

Latest 100
Downloads v6
Currently popular Downloads

Banner System v2.0.4 2269
Video Gallery 1560
Extreme Theme Editor 1257
Fuzed Shoutbox 1066
Seoname.php 1016
Icon Package 2.0 879
Extended Profile ... 782
News.php 699
Tabbed welcome panel 646
EXTboard 583

Latest Downloads


Banner System v2.0.4 2269
Last comments 102
Language switcher panel 319
Admin Submission Panel 130
Admin private messag... 253
Google Sitemap Fast 144
ExtBoard 1.2 430
EXTboard 583
v6.01.18 - v6.01.19 74
v6.01.19 FULL 240

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
Netrix
Smokeman
Elyn @ MrRusty
Diemux
Donate
Shoutbox
You must login to post a message.

17/05/2012 00:59
spam cleaned up

16/05/2012 05:55
I deleted forum posts but I don't have user banning or shoutbox editing permission or I would take care of those too...

15/05/2012 02:33
andredrake , Silvie Spam!! Confused perde

03/05/2012 22:00
El-nino.ugu.pl <---- Fanpage Fernando Torres PL / ENG

03/05/2012 21:34
Hi, everybody, it's been a while, since I was here...

01/05/2012 06:13
Bye!hi

28/04/2012 08:35
tomeck there is one in the downloads here check it out

23/04/2012 07:03
This is the theme of the site joga the theme of perde perde

22/04/2012 16:12
Hello, i need facebook login for fusion 7.01.5 can you help me ? Thumb Up!

21/04/2012 11:05
How i can disable the right click option in all pages over the site?

Member Poll
Which version of PHP-Fusion are you using?









You must login to vote.
Advertiser
One-click Translation
Translate This Site

Online Stats
Guests online: 4
Members online:
no members online


registered members: 25040
newest member: Dave92

user today: 3724
user online: 4
Max. onlinerecord: 86
Max. per day: 32490
user yesterday: 4992
user month: 137553
Entire users: 3839436

last 24h:
























In memoriam

Nick Jones
1973-2011
Render time: 6.37 seconds - 84 Queries 17,998,848 unique visits