This question already has an answer here:
I have a PHP string
$string = "1167-07-04";
// Yes, looks like a DATE but it´s not.
I´m trying to UPDATE a MYSQL field (varchar)
$sql = "UPDATE table SET `field1` = $string";
But... The problem is that makes a substract and puts the value 1156. I need to put 1167-07-04
Anyone knows HOW? Thanks a lot.
</div>
Firstly, you need to take a look at prepared statements. Please, for the love of software, take a look at prepared statements!! Secondly, your value is a string so you need to put some single quotes around it. Looks like you have a lot to learn about making queries, so here are two links for getting started in PHP:
MySQLi: http://php.net/manual/en/book.mysqli.php
PDO: http://php.net/manual/en/book.pdo.php
I highly recommend taking the time to choose one of these extensions and spending the time to learn them well. There is no room for shortcuts when it comes to working with databases in web applications.
The simple answer without any preaching is all string values even when in a variable should be wrapped in quotes. Thats quotes and not backticks.
$sql = "UPDATE table SET `field1` = '$string'";