Jump to content

Updating multiple fields in a db with one query.


refiking

Recommended Posts

I have 16 fields that I need to update and I'd like to do it with one query as opposed to 16 separate ones.  When I tried this, it didn't work:

 

$change = "UPDATE gatable SET (r1g1,r1g2,r1g3,r1g4,r1g5,r1g6,r1g7,r1g8,r1g9,r1g10,r1g11,r1g12,r1g13,r1g14,r1g15,r1g16) VALUES ('$r1g1','$r1g2','$r1g3','$r1g4','$r1g5','$r1g6','$r1g7','$r1g8','$r1g9','$r1g10','$r1g11','$r1g12','$r1g13','$r1g14','$r1g15','$r1g16')";

Did you actually try to execute the query with mysql_query()? Try this:

 

<?php

$change = "UPDATE gatable SET (r1g1,r1g2,r1g3,r1g4,r1g5,r1g6,r1g7,r1g8,r1g9,r1g10,r1g11,r1g12,r1g13,r1g14,r1g15,r1g16) VALUES ('$r1g1','$r1g2','$r1g3','$r1g4','$r1g5','$r1g6','$r1g7','$r1g8','$r1g9','$r1g10','$r1g11','$r1g12','$r1g13','$r1g14','$r1g15','$r1g16')";
$result = mysql_query($change)or die(mysql_error() . "<p>With Query $change");

?>

 

Copy and paste the error if you get one.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.