Ash
Ash

Reputation: 13

Simple HTML form and PHP throwing error

I am just calling a simple PHP script through a HTML form.

An error is thrown everytime : "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"

I have defined the encoding both in PHP as well as HTML as UTF-8 (please refer to code below). I am unable to solve this problem despite searching all over the web.

HTML code :

<head>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8">
    <meta content="UTF-8" http-equiv="encoding"/>
    <title>Test</title>
</head>

<body>
    <div align="center">
    <form action= "google1.php" method="get" accept-charset="UTF-8" >
             Enter Your Name:
            <INPUT TYPE = "text" NAME = "student"> <BR>
            <!--input name="q" type="text"-->
            <br/ > 
            <input name="btnG" type="submit"  value ="test">
        </form>
    </div>
</body>

PHP Code

header("Content-type: text/html; charset=UTF-8");
print "<pre>";
print_r($_GET);
print "</pre>";

The result after submitting the button (along with the error) is :

"; print_r($_GET); print ""; ?>

I am using XAMPP. I tried to edit .htaccess (added : AddType 'text/html; charset=UTF-8' html) as suggested in some of the solutions over internet but that also did not help.

I found a site where there is a simple form which calls a PHP script again. http://www.tjhsst.edu/~dhyatt/superap/form1.html . When I try to submit value in the form, I get the same error.

So I thought, this could be a browser problem and I changed the default encoding of my browser to UTF-8. But this also did not help.

I am a novice in web programming and trying to learn. Appreciate if any one can help.

Thanks, Ashutosh

Upvotes: 1

Views: 1025

Answers (2)

Viktor S.
Viktor S.

Reputation: 12815

It looks like you have some issue with opening/closing tags.

Ensure that you have php code wrapped with <?php and ?> in your process1.php3 (Some details: http://php.net/manual/en/language.basic-syntax.phpmode.php) Like here:

<?php
   header("Content-type: text/html; charset=UTF-8");
   print "<pre>";
   print_r($_GET);
   print "</pre>";
?>

UPD:

After a long session of question/answer finally appeared that OP were opening file with a form using file:// protocol. Like file:///C:/xampp/htdocs/example/form.html and form were submitted to file:///C:/xampp/htdocs/example/google1.php?... As apache works with HTTP protocol only, PHP were not executed actually.

Upvotes: 3

Bhavik Shah
Bhavik Shah

Reputation: 2291

Your Code:
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">

Correct code:
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />

You have forget to put slash at the end of meta-tag. You have not closed the meta tag.
Though, its not very crucial, as you have tried everything. Try this one too. It might work for you.

Upvotes: 0

Related Questions