0

I have a table in Database PhpMyAdmin with certain values, and I want to UPDATE only ONE value of these, WHERE the latest initial_date (TIMESTAMP) is.

I write down here the code I generated as an example, so you can see I actually obtain that date value through SELECT, but I don't manage to UPDATE it. Thank you very much.

$select = "SELECT MAX(initial_date) AS max_value FROM services WHERE matricula = '" . $_POST["taxi"] . "'";
$select_results = mysqli_query($conexion, $select);
while($row = mysqli_fetch_array($select_results)){
    echo $row['max_value'];
    $update_carrera = "UPDATE services SET";
    $update_carrera .= " costo_carrera = costo_carrera + " . $_POST["costo_carrera"] . ",";
    $update_carrera .= " final_date = CURRENT_TIMESTAMP";
    $update_carrera .= " WHERE initial_date = ''";
    $update_carrera_results = mysqli_query($conexion, $update_carrera);
}

I leave WHERE initial_date = '' empty so you can tell what should it be. I get a correct date value in the echo $row['max_value']; if I solve the WHERE with a WHERE initial_date = '20160405153315' (INTEGER), but I don't want to put myself the integer, of course I want to get the newest date from the table database.

chris85
  • 23,846
  • 7
  • 34
  • 51
D'Artagnan
  • 11
  • 1
  • 3
  • 1
    [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). – Jay Blanchard Apr 05 '16 at 17:03
  • Thank you Jay, but first I need to find out how to UPDATE the values WHERE the newest DATE is in the table. I don't know how yet. – D'Artagnan Apr 06 '16 at 19:31

0 Answers0