August 01 2010 00:04:48
Navigation
Last Seen Users
AcertOnline
Samp00:06:10
mojitoman00:07:18
Deus00:11:30
davidbusch00:13:43
Assensvej01:04:43
hooz01:12:04
Narco01:13:28
KissXme01:23:56
schweinebob01:42:27

Members: 15,625
Newest: KissXme
Blogs
Diemux
» 18-09-2009 - Say ...
Diemux
» 10-07-2009 - Will...
Diemux
» 24-06-2009 - Blog...
elyn
» Elyn + Streamyx (...
Diemux
» 19-05-2009 - Thin...
Diemux
» 15-05-2009 - Week...
Diemux
» 13-05-2009 - Comp...
elyn
» Number 1925
Diemux
» Number One
Things to Do
Latest Articles
A tour through the n...
Protect your Fusion ...
Change your database...
Handling MySQL Datab...
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
Downloads v7
Currently popular Downloads

FusionBoard 4 3859
Video Gallery 2749
Professional Down... 2497
Photoalbum Mass U... 2427
Avatar Studio 2287
Extended Profile 1863
XHTML mod for mod... 1808
Button panel 1789
VArcade 2.1 1778
HighSlide Gallery... 1762

Latest Downloads


XHTML mod for modern... 1808
Pimped-Fusion v0.08.01 4
Update Package v0.08.01 0
Support Panel-Skype 7
Header Weather Widget 59
Forum Thread List Pa... 23
Meta Keywords/Descri... 73
Security System 127
User Field: US State... 24
Forum sub categories... 135

Latest 100
Downloads v6
Currently popular Downloads

Banner System v2.0.4 1648
Video Gallery 1183
Extreme Theme Editor 887
Fuzed Shoutbox 789
Seoname.php 736
Icon Package 2.0 687
Extended Profile ... 648
News.php 578
EXTboard 549
Tabbed welcome panel 518

Latest Downloads


Google Sitemap Fast 46
ExtBoard 1.2 381
EXTboard 549
v6.01.18 - v6.01.19 27
v6.01.19 FULL 81
Birthday 111
Moneybookers 43
User info 100
Link to us 259
jNews.php 339

Latest 100
Provider
PHPfusion-mods.net is hosted at:

110MB
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
#1elyn on December 10 2008 04:08:46
elyn
i see, this just seconded my idea that php fusion does not allow custom mysql error message, unless we mod the maincore >.>
#2alternator on October 11 2009 10: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
Rizald 'Elyn' Maxwell
Diemux
Netrix
Donate
Shoutbox
You must login to post a message.

31/07/2010 17:39
Never mind. Got it now.

31/07/2010 17:32
I am looking for the developers pack that used to be here. This pack gave you the basic outline to start from.

30/07/2010 14:35
I'm new here, lurking and downloading ur hard work now ! Cheers!

30/07/2010 08:47
thankkkkks........
..................
..................
........... Cheers! Ventilator

29/07/2010 19:25
Sorry about the previous Shouts and post in theforums regarding lisence. I got a bit power hungry when I USED to be crew. Thumb Up!

29/07/2010 09:54
... and now he's banned. Thumb Up!

29/07/2010 08:55
hyzhy = spambot

28/07/2010 16:26
Thumb Up!

28/07/2010 16:20
@AKC_Pico said he purchased the licence and you still left him a message...

28/07/2010 16:14
Is "PHP-Fusion By Nick Jones" is sufficient?

Advertiser
One-click Translation
Translate This Site

Render time: 0.16 seconds 5,063,493 unique visits