M
M
Meeeeeeeeeeepo2020-03-02 23:08:42
PHP
Meeeeeeeeeeepo, 2020-03-02 23:08:42

Why does sql query only update numeric values?

The SQL query updates the fields in the database only if the input value is a numeric format, in the case of text, nothing happens at all.
---------------
PHP script code:

require_once('../blocks/connection_db.php');
  $article = $_GET['article'];
  $name = $_GET['name'];
  $description = $_GET['description'];
  $parameters = $_GET['parameters'];
  $manufacturer = $_GET['manufacturer'];
  $cost = $_GET['cost'];
  $request = "UPDATE products SET name = '$name', description = '$description', parameters = '$parameters', manufacturer = '$manufacturer', cost = '$cost' WHERE article = $article";
  $connection_db -> query($request);
  header('Location:/within.php');

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Pankov, 2020-03-02
@trapwalker

Because collecting sql in this way (by setting strings and concatenating) is a very bad idea. Use parameterized queries. Even in. Php can and should do it.

E
entermix, 2020-03-02
@entermix

Because the $article variable is not wrapped in parentheses:

$request = "UPDATE products SET name = '$name', description = '$description', parameters = '$parameters', manufacturer = '$manufacturer', cost = '$cost' WHERE article = $article";

--->
$request = "UPDATE products SET name = '$name', description = '$description', parameters = '$parameters', manufacturer = '$manufacturer', cost = '$cost' WHERE article = '$article'";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question