help me please, i need to save the values of everything in the table but the value that can be save is the value of the last record only. i have this code below.

$answer = mysql_query("SELECT * FROM tbl_empinfo where empdept = '$userdept'") or die(mysql_error());	
	
	echo "<table border = '1' bordercolor = '#0000FF' align = center cellpadding = 4 cellspacing=0>";
	echo "<tr>";
	echo "<th><strong><font face = 'Arial' size = 2>ID Number</font></strong></th>";
	echo "<th><strong><font face = 'Arial' size = 2>Name</font></strong></th>";
	echo "<th align = center><font face = 'Arial' size = 2>Incoming Destination</font></th>";
	echo "<th align = center><font face = 'Arial' size = 2>Time In</font></th>";
	echo "<th align = center><font face = 'Arial' size = 2>Outgoing Destination</font></th>";
	echo "<th align = center><font face = 'Arial' size = 2>Time Out</font></th>";
	echo "</tr>";

while($row = mysql_fetch_array($answer))
		{
			$counter =1;
			$counter++;
			$name = $row['empname'];
			$idno = $row['empidno'];
			$shuttle = $row['empshuttle'];
			$area = $row['emparea'];
			echo "<tr><td><font face=Arial size=2>$idno</font></td>";
			echo "<td><font face=Arial size=2>$name</font></td>";
			echo "<td><font face=Arial size=2><select name='incdestination' id='incdestination'><option>$shuttle</option>
                <option>Alabang</option>
                <option>Balibago</option>
                <option>Calamba</option>
                <option>Carmona</option>
                <option>Mayapa</option>
                <option>Paseo</option>
              </select></font></td>";
			$incdestination = $_POST['incdestination'];
			echo "<td><select name='timein' id='timein'>
                <option>6am</option>
                <option>8am</option>
                <option>10am</option>
                <option>2pm</option>
                <option>6pm</option>
                <option>8pm</option>
                <option>10pm</option>
                </select></td>";
			$timein = $_POST['timein'];
			echo "<td><select name='outdestination' id='outdestination'><option>$shuttle</option>
                <option>Alabang</option>
                <option>Balibago</option>
                <option>Calamba</option>
                <option>Carmona</option>
                <option>Mayapa</option>
                <option>Paseo</option>
              </select></font></td>";
			$outdestination = $_POST['outdestination'];
			echo "<td><select name='timeout' id='timeout'>
                <option>6am</option>
                <option>8am</option>
                <option>10am</option>
                <option>2pm</option>
                <option>4pm</option>
                <option>6pm</option>
                <option>8pm</option>
                <option>10pm</option>
                </select></td></tr>";
			$timeout = $_POST['timeout'];
				
				$save = $_POST['save'];
				$cancel = $_POST['cancel'];
				
				if ($save == 'Save')
				{
					$result = mysql_query("SELECT * FROM tbl_shuttledestination WHERE empname = '$name' AND empdate = '$datenow'") or die(mysql_error()); 
					$resultRow = mysql_num_rows($result);
					
					if ($resultRow == '0')
						{
						mysql_query("INSERT INTO tbl_shuttledestination (empidno, empname, empdept, emparea, empincdest, emptimein, empoutdest, emptimeout, empdate, empflag) 
					VALUES ('$idno', '$name', '$userdept', '$area', '$incdestination', '$timein', '$outdestination', '$timeout', '$datenow', '0')") 
						or die(mysql_error());  
						}
					else if ($resultRow != '0')
					{
						mysql_query("UPDATE tbl_shuttledestination SET empincdest = '$incdestination', emptimein='$timein', empoutdest = '$outdestination', emptimeout = '$timeout' WHERE empdept = '$userdept' AND empdate = '$datenow'") or die(mysql_error()); 
					}
		
					echo "<META HTTP-EQUIV=REFRESH CONTENT='0; URL=http://**.**.***.***/aaaa/bbb/ccc.php'>";
				}
				
				else if ($cancel == 'Cancel')
				{
				echo "<META HTTP-EQUIV=REFRESH CONTENT='0; URL=http://**.**.***.***/aaaa/bbb/ccc.php'>";
				exit;
				}
				
		
			 
		}
		 echo "</table><br/>";
		echo "<input name='save' type='submit' id='save' value='Save' />";
        echo "<input name='cancel' type='submit' id='cancel' value='Cancel' />";

Aneeka,

The usual pattern for this is to break it up into two pages. One is a list of employees that displays the data in a report. A link stores the key for each record and points to an edit form where a single employee record is edited. (That's the approach you'll see in phpMyAdmin for example.)

Making the entire contents of the table editable at once won't scale well; consider how much HTML gets generated when you reach 100 employees? The form gets progressively slower to work with. Do you really need to edit the entire contents of the table at once?

If not, consider the list to be something like this:

...
while($row = mysql_fetch_array($answer))
{
	printf('<tr><td>%1$d</td><td><a href="/?action=edit&id=%1$d">%s</a></td><td>%s</td><td>%s</td></tr>', $row['empidno'], $row['empname'], $row['empshuttle'], $row['emparea']);
}
...

Have the link in each record point to an edit form that handles just one record at a time. The id for the record will be passed via the querystring variable 'id' ($_GET).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.