missing form post data with special character

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mehnaz
Forum Newbie
Posts: 20
Joined: Mon Jun 02, 2008 7:49 pm

missing form post data with special character

Post by Mehnaz »

Hi,

I am passing some value from html text area(lets say 'name') to a php script. It works fine when the name doesnt have any special character. but for the case of input data 'u&e' it is passing only 'u' and the rest is not passing in post variable.

Please help

Mehnaz
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: missing form post data with special character

Post by pbs »

Use this function when you enter any descriptive content.

Code: Select all

 
function quote_smart($value)
{
    // Stripslashes
    if (get_magic_quotes_gpc()) 
    {
        $value = stripslashes($value);
    }
    // Quote if not a number or a numeric string
    if (!is_numeric($value)) 
    {
        $value = "'" . mysql_real_escape_string($value) . "'";
    }
    return $value;
}
 
feden
Forum Newbie
Posts: 2
Joined: Thu Jan 14, 2010 12:58 pm

Re: missing form post data with special character

Post by feden »

I think you need to check character encoding. It should be UTF-8 on all files / databases
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: missing form post data with special character

Post by AbraCadaver »

Mehnaz wrote:Hi,

I am passing some value from html text area(lets say 'name') to a php script. It works fine when the name doesnt have any special character. but for the case of input data 'u&e' it is passing only 'u' and the rest is not passing in post variable.

Please help

Mehnaz
You need to show an example and some code. This works fine for me.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Mehnaz
Forum Newbie
Posts: 20
Joined: Mon Jun 02, 2008 7:49 pm

Re: missing form post data with special character

Post by Mehnaz »

I am using Ajax with prototype to post the form request from index.php page to prefferdterm.php page like this to fill a div using "innerHTML". Here is my code

Code: Select all

<html>
    <title>Term Study Interface</title>
    <head>  
        <meta http-equiv=Content-Type content="text/html; charset=utf-8"> 
 
        <script type="text/javascript" src="prototype.js"></script>
        <LINK REL=StyleSheet HREF="style.css" TYPE="text/css">
        <script>
 
            function sendRequest() {
                $('dvloader').show() ; 
                new Ajax.Request("prefferdterm.php", 
                    { 
                    method: 'post', 
                    postBody: 'name='+ $F('name'),
                    onComplete: showResponse 
                    });
                }
 
            function showResponse(req){
                $('dvloader').hide() ; 
                $('show').innerHTML= req.responseText;
                
            }
            
            function popUp(URL) {
                day = new Date();
                id = day.getTime();
                eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,left=170, top=10,statusbar=0,menubar=0,resizable=1,width=1100,height=900');");
            }
 
        </script>
    </head>
 
    <body>
        <div style="display:none" id="dvloader"><img src="ajax-loader.gif" /></div> 
        <form id="test" onsubmit="return false;">
            <input type="submit" value="Enter Term" class = "enterbuttonclass" onClick="sendRequest()">
            <div><textarea name="name" rows="1" cols="12"  id = "name" class = "termclass"></textarea></div>
                    
        </form>
                
        <div id="show" ></div>
 
                
    </body>
 
</html>
 
I have included
<meta http-equiv=Content-Type content="text/html; charset=utf-8">

in index.php <head> section but in requesting page only 'u' out of 'u$e" is passing. When I checked the passed value in prefferdterm.php using the code below:

$term = $_POST["name"];

echo $term;

In outputs only 'u' instead of 'u&e'.

In my case user can use any sepcial character in the input form but I am stuck how to deal with it.

Mehnaz
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: missing form post data with special character

Post by AbraCadaver »

This is a javascript or ajax problem. Since you are posting with javascript, you need to run the data through javascript escape(), or your ajax library may have a method for encoding the data.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Mehnaz
Forum Newbie
Posts: 20
Joined: Mon Jun 02, 2008 7:49 pm

Re: missing form post data with special character

Post by Mehnaz »

Thanks for all the replies.

javascript escape() did my job :)

mehnaz
Post Reply