0

Hi need to modify this php script to update the values in my db row instead of delete and creating again. I have other fields in the same row I don't want to touch. Can you help me? Here is the code:

$data = array(
    'email' => "'".$connection->real_escape_string($_POST['Email'])."'",
    'plan' => "'".$connection->real_escape_string($_POST['Plan'])."'",
    'date_created' => 'NOW()',
    'ip' => "'".$_SERVER['REMOTE_ADDR']."'",
);
$sql = "REPLACE INTO `".$SETTINGS["data_table"]."` (`".implode("`, `", array_keys($data))."`)VALUES(".implode(", ", array_values($data)).")";
if ($connection->query($sql) === TRUE) {
    $last_id = $connection->insert_id;

Tried to replace "REPLACE INTO" with "UPDATE" but obviously not worked

shingo
  • 18,436
  • 5
  • 23
  • 42
  • Have you looked at how the update syntax looks like? See e.g. [PHP UPDATE prepared statement](https://stackoverflow.com/a/44051644) – Solarflare Sep 02 '23 at 11:12
  • What **exactly** is not working with the given code? Is this a PHP problem, or a MySQL problem? – Nico Haase Sep 02 '23 at 11:33
  • 1
    Also, be warned that your code is highly vulnerable to SQL injection. Have a look at prepared statements to avoid getting hacked – Nico Haase Sep 02 '23 at 11:33

0 Answers0