B
B
bob_meister2016-07-10 16:48:34
SQL
bob_meister, 2016-07-10 16:48:34

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'

The bottom line is that I'm trying to insert a field ID in a table in PHP code.
And instead of inserting text like this into the field:
<?php header("Location: <?=SITE_NAME;?>/index.php?action=view_ads&id=4")?>
there is only an ID, i.e. 4.
Can you tell me what and where I forgot to put?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aleksey Ratnikov, 2016-07-10
@bob_meister

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 question

Ask a Question

731 491 924 answers to any question