0

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.

Tom
  • 91
  • 9

2 Answers2

2

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'";
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
0

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.

samrap
  • 5,595
  • 5
  • 31
  • 56
  • you are completely right. the amount of programming I have done this week has apparently made me into an idiot. let me update that – samrap Sep 04 '15 at 22:45