Welcome to Webune Support forums

if you like programming in php and you have problems entering your data or a string into your MySQL database when the strin contains the ampersand charater: &

we will show you some times what you can use to be sure that this character is entered connected.

lets say for example, i have this PHP code:

<?php
$string = "AT&T Email"
$Sql = "INSERT INTO mytable SET keyword='$string'";
?>


if you were to try to enter this code into your database, you probably would not get any error

but how about if you are getting the value of the string from a URL, like this for example:

the url is: http://www.example.com/example.php?string=at&t
<?php
$string = $_GET['string'];
$Sql = "INSERT INTO mytable SET keyword='$string'";
?>


the only characters that would be inserted into your dabase will be "AT"
any character after & will not be entered.

so how do you solve this.

you will have to correct the url to look like this:
http://www.example.com/example.php?string=at%26t

you see what i did? i change & to %26

%26 is the the encoded code for &

to encode url, PHP provides the urlencode() function. to decode it you would simply use the urldecode() function

hope that helps

IMPORTANT: this tutorial only applies in situations where you are getting the string from the url,

it its a regular string embed into HTML, then you would have to use htmlspecialchars() function for example

<?php
$string = htmlspecialchars("I HAVE AT&T EMAIL ACCOUNT");
echo $string;
?>

in the above example, the value of $string would be the HTML code like this:
&quot;I HAVE AT&amp;T EMAIL ACCOUNT&quot;