March 12 2010 05:37:41
Navigation
Last Seen Users
samoOnline
everyhao357< 5 mins
combro< 5 mins
Kohl< 5 mins
macjon< 5 mins
afoster00:38:04
FeryCsaby00:42:23
Chibanga00:54:19
ekingwww01:03:02
Thayle01:09:48

Members: 13,495
Newest: combro
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
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...
Upgrading to PHP-Fus...

View all articles
Downloads v7
Currently popular Downloads

FusionBoard 4 3164
Video Gallery 2275
Professional Down... 2232
Photoalbum Mass U... 2053
Avatar Studio 1996
Extended Profile 1687
VArcade 2.1 1584
HighSlide Gallery... 1560
XHTML mod for mod... 1443
Button panel 1439

Latest Downloads


User Info [Remade] 274
BBcode: AVI 6
Pimped PHP-Fusion 4
XHTML mod for modern... 1443
Banner Rotater 866
Who's Where Panel 733
VU Tab Panel 383
Viewlog Script 186
Usergroup Management 659
Unauthenicated User 185

Latest 100
Downloads v6
Currently popular Downloads

Banner System v2.0.4 1412
Video Gallery 1065
Extreme Theme Editor 815
Fuzed Shoutbox 705
Seoname.php 664
Icon Package 2.0 651
Extended Profile ... 610
EXTboard 542
News.php 541
Tabbed welcome panel 489

Latest Downloads


Google Sitemap Fast 5
ExtBoard 1.2 366
EXTboard 542
v6.01.18 - v6.01.19 20
v6.01.19 FULL 54
Birthday 88
Moneybookers 32
User info 74
Link to us 245
jNews.php 312

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
Rizald 'Elyn' Maxwell
Diemux
Netrix
Donate
Shoutbox
You must login to post a message.

12/03/2010 04:34

12/03/2010 01:40
Whats up!? Wink

11/03/2010 23:02
:evilish Confusedupport question? Post in the forums!

11/03/2010 16:55
New spammer: deal202 That really suxx!

11/03/2010 13:57
Support question? Post in the forums!

11/03/2010 02:24
@Diemux: Important PM for you.

10/03/2010 20:10
Cool, added the download again Smile. Also cleaned inbox Smile

10/03/2010 13:41
Ohh - your inbox is full btw!

10/03/2010 13:40
@Diemux: I've re-coded the naptzer_user_info - from the "z-dump". You can DL it from here: www.dvdside.dk/do.
..r_info.zip

10/03/2010 00:07
So if you have some spare time Smile

Advertiser
One-click Translation
Translate This Site

Render time: 0.19 seconds 3,992,014 unique visits