Answer the question
In order to leave comments, you need to log in
How to update data in mysql when post request is sent?
Good day, there is a direct post request like: domain.ru/form.php?date=2016-01-15 03:00:57&name=toster , which writes id (A_I), time, name to the database.
Everything works as it should, but there was a need for exactly the same request, in the same UPDATE handler (overwrite the name without changing the time and id) data. So, when I access the same link, but changing the name (domain.ru/form.php?date=2016-01-15 03:00:57&name=name) , nothing happens, no data is added, no data is changed, how can this be fixed?
Form code:
require 'connect.php';
$date = trim($_REQUEST['date']);
$name = trim($_REQUEST['name']);
$insert_sql = "INSERT INTO box (date, name)" .
"VALUES('{$date}', '{$name}');";
mysql_query($insert_sql);
Answer the question
In order to leave comments, you need to log in
mysql_ -Deprecated and will be removed soon. Use mysqli + prepared queries.
replace replace with require_once .
$insert_sql = "INSERT INTO box (date, name)" .
"VALUES('{$date}', '{$name}')" .
"ON DUPLICATE KEY UPDATE name={$name};";
mysql_query($insert_sql);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question