Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9011213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:40:15+00:00 2026-06-16T02:40:15+00:00

I made a form that users can fill out and it checks if the

  • 0

I made a form that users can fill out and it checks if the user correctly inserts the email.

  • If it returns false: the user gets to see an error message.
  • If it returns true: it will show the user a confirmation message but it will also INSERT the data into the database.

So the problem occurred when I tried to add the form in the PHP file so I could make an alert or give the user the error message on the same page. I started to get this error:

The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol.

So I tried to restore this by reverting to the older version, I had to cut and paste a few pieces of code but nothing too complicated. For some strange reason I still get this error. Naturally I checked the similar topics on this issue here on Stackoverflow but none of the answers got me any further. For example adding the meta information in the header of the page,I also created a PHP header like this: header('Content-type: text/html; charset=utf-8');After that I read some articles about this error but none helped me resolve this issue.

Here is an example of my code. It is this page I get the error on:

 <?php    
include_once('credentials.php');
mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
include_once('functions.php');

 $apples = sanitize($_POST['Apple']);
 $oranges = sanitize($_POST['Orange']);
 $melons = sanitize($_POST['Melon']);
 $pears = sanitize($_POST['Pear']);
 $strawberries = sanitize($_POST['Strawberry']);
 $grapes = sanitize($_POST['Grape']);               
    if($_POST['Grape'] == 'Yes')
    { $grapes = 1; }
    else
    { $grapes = 0; } 
$blueberries = sanitize($_POST['Blueberry']);

if (checkStrawberries($strawberries) == true) {    
    mysql_query("   INSERT INTO tablename (Name, Weight, Color, Ripeness, Age, Origin, Destination) 
            VALUES ('$apples', '$oranges', '$melons', '$Pears', '$strawberries', '$grapes', '$blueberries') ");

    or die(mysql_error()); 

    echo '<!DOCTYPE html>   
            <html>
                <head>
                    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
                </head>
                <title>Page</title>
                <body>
                    True
                    <a href="../index.php">home</a>
                </body>
            </html>';
} else {
    echo '<!DOCTYPE html>   
            <html>
                <head>
                    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
                </head>
                <title>Pagina</title>
                <body>
                    False
                    <a href="../index.php">home</a>
                </body>
            </html>';
}
?>

I had to rename the variables and classes as they have strong relations with the company I work for.

EDIT: This error is being produced by the console log in Firefox using Firebug.

EDIT 2: Changed the var and function names to avoid confusion and to illustrate the exchange of data within this application.

EDIT 3: I tried to figure out what exactly in my code is producing this error, because I tested the encoding part with the test case presented to me below by Dobromir Velev and that worked just fine. I decided to comment out the IF ELSE statement and I didnt get an error. So this seems to corrupt the page.

I removed the echo’s for now as it didn’t add any value to this particular challenge.

if (checkStrawberries($strawberries) == true) {    
    mysql_query("INSERT INTO tablename (Name, Weight, Color, Ripeness, Age, Origin, Destination) 
    VALUES ('$apples', '$oranges', '$melons', '$Pears', '$strawberries', '$grapes', '$blueberries') ");
    or die(mysql_error());
} else {
    echo 'FALSE';
}

The function checkStrawberries is this:

function checkEmail($email) {
if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) {
return false;
}
return true;
}

The function sanitize is this:

function sanitize($dirty){
$clean = htmlspecialchars($dirty);
$cleaner = mysql_real_escape_string($clean);
return $cleaner;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:40:16+00:00Added an answer on June 16, 2026 at 2:40 am

    After some discussion on the PHP chat, it seems the problem comes from the extra semicolon

    From :

    mysql_query(); or die();
    

    To :

    mysql_query() or die();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a form so that users can register their email address for a
I have made an normal form that you can enter a user´s fullname in
I have about 20 text fields on a form that a user can fill
I have a dynamic form that adds users to the site, made so you
Form is made from a function that prints out all rows that are awaiting
I have a form which a user can fill in x times with the
I made a .NET Windows form that allows users to view a particular document
I have an upload form where users can upload images that are currently being
I have a form on my Django site (made with ModelForm) where users can
I have a user control on a form that can spawn several non-modal child

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.