Answer the question
In order to leave comments, you need to log in
Problem in SQL query with UPDATE?
Hello. I'm trying to add a PHP code to the database with a field ID in which I add this same PHP code.
The request is like this:
UPDATE `test_table` SET `id_to_col`= '<?php header("Location: <?=SITE_NAME;?>/index.php?action=view_ads&id='+test_table.id+'")?>' WHERE id = '4'
Answer the question
In order to leave comments, you need to log in
MySQL does not have a concatenation operator, + is an addition operator, instead there is a CONCAT() function. In this case, you got 4 because MySQL cast all operands to numbers, resulting in 0 + 4 + 0 = 4.
Replace + with CONCAT():
UPDATE
`test_table`
SET `id_to_col`= concat('<?php header("Location: <?=SITE_NAME;?>/index.php?action=view_ads&id=', test_table.id ,'")?>')
WHERE id = '4'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question