Page 1 of 1

Updating multiple columns in MySQL DB

Posted: Fri Jun 10, 2011 8:00 am
by A7x
Hi, the topic says it all here's my code:

Code: Select all

if (isset($_POST['go']))
{
	foreach ($_POST['uniqueID'] as $id)
	$update = mysql_query("UPDATE mytable SET status='".$_POST['select']."' WHERE id='".$id."'");
}
This code is not working at all.
$_POST['select'] is a dropdown list contains 3 values. I want to take one of the selected values and put this value into a column in mysql when submit button is pressed. FYI: I am updating multiple columns in my DB.

$_POST['uniqueID'] is a hidden field with value $row['id'] pulled from database.

I have also tried to use this code:

Code: Select all

if (isset($_POST['go']))
{
	$update = mysql_query("UPDATE mytable SET status='".$_POST['select']."' WHERE id='".$_POST['uniqueID']."'");
	
}
This code updated just last record in my DB :\

Sorry I'm new to php and I'm stuck, I need to know what am I doing wrong. thanx

Re: Updating multiple columns in MySQL DB

Posted: Fri Jun 10, 2011 8:06 am
by social_experiment
Is $_POST['uniqueID'] an array? Paste your form (html) code aswell.

Re: Updating multiple columns in MySQL DB

Posted: Fri Jun 10, 2011 9:14 am
by A7x
Here's the code;

Code: Select all

<form action="" method="post" name="form1">
<select name="select">
  <option value="Value1">Value1</option>
  <option value="Value2">Value2</option>
</select>
<input type="hidden" name="uniqueID" value="<?php echo $row['id']; ?>"   />
<input type='submit' name="go" value="Go"  />
</form>

Re: Updating multiple columns in MySQL DB

Posted: Tue Jun 14, 2011 6:45 am
by social_experiment

Code: Select all

<input type="hidden" name="uniqueID" value="<?php echo $row['id']; ?>"   />
$_POST['uniqueID'] isn't an array that is why only 1 record is being updated.