83

I'm trying to make a donation center which I use the source code from Totorialzine.

Everything works fine for me at this moment so far but the only problem I was struggling on and trying to look at for the whole day and can't figure what is actually wrong with the code exactly

here is what I get when I submit the comment on the page when my visitors donate.

Fatal error: Call to undefined function mb_strlen() in /home/yoursn0w/public_html/livetv/premium/thankyou.php on line 14

and here is the code in the php file.

<?php

require "config.php";
require "connect.php";

if(isset($_POST['submitform']) && isset($_POST['txn_id']))
{
    $_POST['nameField'] = esc($_POST['nameField']);
    $_POST['websiteField'] =  esc($_POST['websiteField']);
    $_POST['messageField'] = esc($_POST['messageField']);

    $error = array();

    if(mb_strlen($_POST['nameField'],"utf-8")<2)
    {
        $error[] = 'Please fill in a valid name.';
    }

    if(mb_strlen($_POST['messageField'],"utf-8")<2)
    {
        $error[] = 'Please fill in a longer message.';
    }

    if(!validateURL($_POST['websiteField']))
    {
        $error[] = 'The URL you entered is invalid.';
    }

    $errorString = '';
    if(count($error))
    {
        $errorString = join('<br />',$error);
    }
    else
    {
        mysql_query("   INSERT INTO dc_comments (transaction_id, name, url, message)
                        VALUES (
                            '".esc($_POST['txn_id'])."',
                            '".$_POST['nameField']."',
                            '".$_POST['websiteField']."',
                            '".$_POST['messageField']."'
                        )");

        if(mysql_affected_rows($link)==1)
        {
            $messageString = '<a href="donate.php">You were added to our donor list! &raquo;</a>';
        }
    }
}

?>

I have my database in the phpMyAdmin uploaded completed

here is where I follow the instruction of the installation

http://tutorialzine.com/2010/05/donation-center-php-mysql-paypal-api/

darrenp
  • 4,265
  • 2
  • 26
  • 22
Ali
  • 9,997
  • 20
  • 70
  • 105
  • 2
    http://www.php.net/manual/en/mbstring.installation.php - You need to either enable or install the mbstring PHP extension to use that function. – hakre Jun 21 '11 at 00:37

10 Answers10

88

The function mb_strlen() is not enabled by default in PHP. Please read the manual for installation details:

http://www.php.net/manual/en/mbstring.installation.php

AJ.
  • 27,586
  • 18
  • 84
  • 94
  • thank you I'm going to look at the link that you provide me now. – Ali Jun 21 '11 at 00:42
  • 1
    mbstring.detect_order mbstring.encoding_translation mbstring.func_overload mbstring.http_input mbstring.http_output mbstring.internal_encoding mbstring.language mbstring.substitute_character here is what I found which one would define the same of what I have to enable if you can please point me to the right one? – Ali Jun 21 '11 at 00:48
  • @Ali - I'm not sure what this is supposed to be. If it's formatted info, you would be better served editing your original question and adding the pertanent info there. – AJ. Jun 21 '11 at 00:49
  • because what I have looked at my php.ini all those mbstring that I can look at all of them and there is only one option that I can enable or disable it and when I enable it there is nothing change and I still get the same error – Ali Jun 21 '11 at 00:54
  • @Ali - can you see these settings in the output from `phpinfo()`? – AJ. Jun 21 '11 at 00:58
  • @AJ well I only see these option in `php.ini` in the WHM (WebHost Manager) which I can see all of the options in there – Ali Jun 21 '11 at 01:01
  • 2
    @Ali - Many systems have multiple instances of the php.ini file, and it can be confusing which one to trust. The best course of action is to implement a test page under your site that simply calls `phpinfo()`. Search the output of that page for "mbstring" module. If you don't see it there, it's not installed. – AJ. Jun 21 '11 at 01:03
  • it seem to be real tough I don't know where to look if that option is actually available for me to enable or not and I'm so scared to play with the php.ini now because the provider keep telling me if anything went wrong I will just lose all my data and then I'm not really expert on the PHP since my computer programming course start on September but I do really want to learn this :( – Ali Jun 21 '11 at 01:13
  • 2
    @Ali - you will not lose any data by creating a PHP page that just calls `phpinfo()`. Please try this per my previous comment, and see if in fact mbstring is installed for your environment. – AJ. Jun 21 '11 at 01:16
  • ok I will search on google on how to call function phpinfo() and see if that can tell me what we are looking for – Ali Jun 21 '11 at 01:19
  • 1
    @Ali - two things: 1. I don't see any evidence of mbstring being installed on your environment. If you have access to do so, you'll need to install it. Refer to the documentation link I provided above. 2. REMOVE THE URL FOR THE TEST PAGE! Your public hostname is visible in the output from `phpinfo()`. You are exposing yourself to risk by publishing your public hostname. My intentions are to help you, but others may have more malicious intentions. – AJ. Jun 21 '11 at 01:25
  • @AJ sorry for not be careful of what I did, I was checking before I post and though all of the information wouldn't really cause anything for me in the risk and didn't know that could cause a problem Thank you!! secondly I'm going to look at the documentation that you provide me and see if I can get the mbstring install on my php. I hope I can do it :) – Ali Jun 21 '11 at 01:28
  • @Ali - no problem. Please understand that unless you have root privileges on your server, you will probably **not** be able to install the mbstring module without cooperation from your hosting provider. – AJ. Jun 21 '11 at 01:33
  • @AJ I have spoke to my provider and they say I have a full right to do whatever on my server but they wouldn't be able to assist me on the installation part so I have to do some research on how to install it via SSH or where to get it install – Ali Jun 21 '11 at 02:00
  • 3
    @AJ I have finally have mbstring installed and now my script working!! here is what I did it was so simple than I thought!!! WHM -> Software -> EasyApache and in Step 5 click on Exhaustive Options List and check the box for Mbstring and proceed with the build process. It's much simpler than trying to do this manually. – Ali Jun 21 '11 at 02:48
  • How do they expect people to know that? The doc for that function doesn't specify any library as a requirement. Super frustrating – LobsterMan Oct 25 '17 at 14:13
49

To fix this install the php7.0-mbstring package:

sudo apt install php7.0-mbstring
Usman
  • 949
  • 9
  • 12
16

For me the following command did the trick

sudo apt install php-mbstring
webmaster
  • 1,960
  • 24
  • 29
7

On Centos, RedHat, Fedora and other yum-my systems it is much simpler than the PHP manual suggests:

yum install php-mbstring
service httpd restart
kubanczyk
  • 5,184
  • 1
  • 41
  • 52
6

For me, this worked in Ubuntu 14.04 and for php5.6:

$ sudo apt-get install php5.6-mbstring
Mona Jalal
  • 34,860
  • 64
  • 239
  • 408
3

PHP 7.2 Ubuntu 18.04

sudo apt install php-mbstring
M_R_K
  • 5,929
  • 1
  • 39
  • 40
3

This worked for me on Debian stretch

sudo apt-get update
sudo apt install php-mbstring
service apache2 restart
Kevin
  • 121
  • 1
  • 4
3

This question looks to be in relation to PHP on Unix. However, for anyone getting to this question for PHP on Windows, see https://www.php.net/manual/en/install.pecl.windows.php.

Since multi-byte string support is a core PHP extension, all that is necessary on Windows is to uncomment this line in your php.ini:

extension=php_mbstring.dll
darrenp
  • 4,265
  • 2
  • 26
  • 22
2

In case Google search for this error

Call to undefined function mb_ereg_match()

takes somebody to this thread. Installing php-mbstring resolves it too.

Ubuntu 18.04.1, PHP 7.2.10

sudo apt-get install php7.2-mbstring
Vladislav Povorozniuc
  • 2,149
  • 25
  • 26
0

The fix for me was to install the php-mbstring package.

For latest PHP version, like:

sudo apt-get install php-mbstring

Or for PHP 7.4, like:

sudo add-apt-repository ppa:ondrej/php

sudo apt-get install php7.4-mbstring

Finally, restart services, for Apache like:

sudo systemctl restart apache2

Or for nginx, like:

sudo service nginx reload

Note that ppa:ondrej/php warns about not supporting end-of-live PHP versions, but at time of writting, they include PHP 5.6 as well.

Top-Master
  • 7,611
  • 5
  • 39
  • 71