I have an issue while inserting data into database using PHP and MySQL. I am explaining my code below.
$description=mysqli_real_escape_string($connect,"Big Rock AGD 6 pk for $8.99 / 15pk $18.49");
$userqry=mysqli_query($connect,'INSERT INTO db_gallery
(description) values ("'.$description.'")');
But after inserting the some special character are coming with description inside table which is given below.
id description
1 Big Rock AGD 6 pk for $8.99 ​/ 15pk $18.49
Here my description column data type is text
and I dont need to insert that ​
special character with original description. Please help me.
Use htmlspecialchars()
.
$description = mysqli_real_escape_string($connect, htmlspecialchars("Big Rock AGD 6 pk for $8.99 / 15pk $18.49"));
// Makes: Big Rock AGD 6 pk for $8.99 / 15pk $18.49
$userqry = mysqli_query($connect,"INSERT INTO `db_gallery`
(`description`) values ('$description')");
When you get the description from the database $
is converted to: $ by HTML.
Switch double and single quotes in your query makes it al lot easier to read. It also doesn't require you to use .
inside the query.
The backticks `
are used around table and column names to prefent mysql reserverd words error.
you need to change table format
1)change database format
ALTER DATABASE Database_Name CHARACTER SET utf8;
2)change table format
ALTER TABLE Your CONVERT TO CHARACTER SET utf8;
after this your probelm will be solved