I am trying to save a string with number and math operator into database. I want to save the face value of string, but php or mysql is calculating the string and then saving it to the database.
For example:
$stringValue = "24/2";
$query = "UPDATE winter";
$query .= " SET value =".$stringValue;
$query .= " WHERE name = 'xyz'";
$result = mysqli_query($connection, $query);
After running the code, I want the value saved in database to be "24/2", but it is being saved as 12.
...SET value = 24/2...; try adding single quotes around it; or better yet, use parameterized queries to avoid "sql injection" vulnerabilities. (Edit: and by "it" I mean around the string value in the query.)"but it is being saved as 12"- Because24/2is 12. Maybe you meant'24/2'as a string?