Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Help update database from while loop

$
0
0

Hello, I have this piece of code it it currently only updates the last value in the databse. I need all of the fields to update there value. Can anyone help me out ?

 

 

   <fieldset>
   <legend>Ticket Categorys</legend>
   <form method='post' action='admin.php?do=ticketCats'>
   <table width='100%' style='background: #dddddd; padding:2px;'>

    <tr style='background: #C4C4C4;'>

    <td style='font-weight: bold;'><center>ID</center></td>

    <td style='font-weight: bold;'>Category</td>

    <td style='font-weight: bold;'><center>Action</center></td>
	


    </tr>
	
	<?

	$color="1";
	
	
	

	
	   $query = mysql_query("
		SELECT *
		FROM ticket_cats
		ORDER BY name ASC
		");
	
	$level2 = array();
	while ($row = mysql_fetch_assoc($query))
	
	{
                $level2[] = array('id'=>$row['id'],'name'=>$row['name']);
	
			
		if($color==1)
		{
		?>
	        <tr style='background: #fff;'>
			<?
			$color="2";
		}
		else
		{	
		// Set $color back to 1
		$color="1";
		}
		?>
					
					
            <td style='width:15px;'><input type='hidden' value='<?echo $id;?>' name='id[]'><center><?echo $id;?></center></td>
            <td><input type='text' name='catname' style='width:400px;' value='<?echo $name;?>'/></td>
            <td><center><input type='submit' name='deleteCat' value='Delete ID:(<?echo $id;?>)' /></center></td>
			</tr>
		<?
	}
	?>
	<tr>
		<td>
			<input type='submit' name='updateAllCats' value='Update Categorys' />
		</td>
	</tr>
  

    </table>
	</form>
	</fieldset>
	
<?

		if(!empty($_POST['updateAllCats']))																		
		{
		$catname = $_POST['catname'];
		$ida = $_POST['id'];

		
		mysql_query("UPDATE ticket_cats SET name='$catname' WHERE id='$ida'");
    
		
		}

?>

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles