0

Ok is there a possibility to update a column instead of a row?

f.e something like that:

$laninpstmt = $db->prepare ("UPDATE table SET column_name WHERE id = :allids");

$laninpstmt->bindParam(':allids', $_POST['input0']);

$laninpstmt->bindParam(':allids', $_POST['input1']);

$laninpstmt->bindParam(':allids', $_POST['input2']);

$laninpstmt->bindParam(':allids', $_POST['input3']);

$laninpstmt->bindParam(':allids', $_POST['input3']);

If i explain the code it's like: Update all the rows(allids) from one column in a table

Raz3rt
  • 69
  • 1
  • 3
  • 11

3 Answers3

2

Running your query without a where clause will update all rows, and if you update a single field it will be the same as updating a column

UPDATE `test` SET `field_5` = 7

Will update table test and set all values in the column field_5 to 7

Jesper Blaase
  • 2,320
  • 16
  • 13
0

You forgot to specify the value for you column_name like that

   UPDATE table SET column_name = 'Some_value here' WHERE id = :allids

i guess you want do this

$laninpstmt = $db->prepare ("UPDATE table SET column_name = Concat(:allids1 , :allids2, :allids3, :allids4) WHERE id = :allids");
$laninpstmt->bindParam(':allids', $_POST['input0']);

$laninpstmt->bindParam(':allids1', $_POST['input1']);

$laninpstmt->bindParam(':allids2', $_POST['input2']);

$laninpstmt->bindParam(':allids3', $_POST['input3']);

$laninpstmt->bindParam(':allids4', $_POST['input4']);
echo_Me
  • 37,078
  • 5
  • 58
  • 78
0

You could use IN:

Apparently, you need to do your own query, see https://stackoverflow.com/a/920523/2575355.

$inputs = array($_POST['input0'], $_POST['input1'], $_POST['input2']);
$allids = implode(', ', $inputs)

$laninpstmt = $db->prepare ("UPDATE table SET column_name WHERE id IN ($allids)");
Community
  • 1
  • 1
Gagaro
  • 752
  • 7
  • 17