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
missing form post data with special character
Moderator: General Moderators
Re: missing form post data with special character
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;
}
Re: missing form post data with special character
I think you need to check character encoding. It should be UTF-8 on all files / databases
- 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
You need to show an example and some code. This works fine for me.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
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.
Re: missing form post data with special character
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
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
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>
<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
- 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
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.
Re: missing form post data with special character
Thanks for all the replies.
javascript escape() did my job
mehnaz
javascript escape() did my job
mehnaz