here is my code for edit user detail but selected id is not showing .only showing last inserted id. please help me for correct this code..
my view code
<?php
//connects to database
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("users", $con);
//select table
$select = mysql_query("SELECT * FROM entryform") or die('No table exist!');
$numrows = mysql_num_rows($select);
echo <<<EOM
<table border='1'>
<tr>
<th>Complaint No.</th>
<th> Name </th>
<th>Department</th>
<th>Problem</th>
<th>Ext no.</th>
<th>IP Add</th>
<th>Remark</th>
<th>Email</th>
<th>Status</th>
<th>Edit /Delete </th>
</tr>
EOM;
while ($row = mysql_fetch_assoc($select))
{
echo <<<EOM
<tr>
<td>{$row['id']}</td>
<td>{$row['Name']}</td>
<td>{$row['Department']}</td>
<td>{$row['Problem']}</td>
<td>{$row['Ext_no']}</td>
<td>{$row['Ip_Add']}</td>
<td>{$row['Remark']}</td>
<td>{$row['Email']}</td>
<td>{$row['status']}</td>
<td><a href='User_update/select.php?id={$row['id']}'>Edit</a> <a href='delete.php'>Delete</a></td>
</tr>
EOM;
}
echo <<<EOTABLE
</table>
EOTABLE;
?>
My select.php page
<?php
mysql_connect("localhost","root","");
mysql_select_db("users") or die("Unable to select database");
$sql = "SELECT * FROM entryform WHERE id = id ";
$result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());
$i = 0;
echo '<table width="50%">';
echo '<tr>';
echo '<td>ID</td><br/>';
echo '<td>Name</td>';
echo '<td>Department</td>';
echo '<td>Problem</td>';
echo '<td>Ext no</td>';
echo '<td>Ip_Add</td>';
echo '<td>Remark</td>';
echo '<td>Email</td>';
echo '<td>status</td>';
echo '</tr>';
echo "<form name='form_update' method='post' action='update.php'>\n";
while ($entryform = mysql_fetch_array($result)) {
echo '<tr>';
echo "<td>{$entryform['id']}<input type='hidden' Name='id[$i]' value='{$entryform['id']}' />";
echo "<td><input type='text' size='12' name='Name[$i]' value='{$entryform['Name']}'/> </td>";
echo "<td><input type='text' size='12' name='Department[$i]' value='{$entryform['Department']}' /></td>";
echo "<td><input type='text' size='40' name='Problem[$i]' value='{$entryform['Problem']}' /></td>";
echo "<td><input type='text' size='10' name='Ext_no[$i]' value='{$entryform['Ext_no']}' /></td> ";
echo "<td><input type='text' size='10' name='Ip_Add[$i]' value='{$entryform['Ip_Add']}' /></td>";
echo "<td><input type='text' size='20' name='Remark[$i]' value='{$entryform['Remark']}' /></td>";
echo "<td><input type='text' size='25' name='Email[$i]' value='{$entryform['Email']}' /></td>";
echo "<td><input type='text' size='10' name='status[$i]' value='{$entryform['status']}' /></td>";
echo '</tr>';
++$i;
}
echo '<tr>';
echo "<td><input type='submit' value='submit' /></td>";
echo '</tr>';
echo "</form>";
echo '</table>';
?>
my update.php page
<?php
mysql_connect("localhost","root","");
mysql_select_db("users") or die("Unable to select database");
$size = count($_POST['Name']);
$i = 0;
while ($i < $size) {
$Name= $_POST['Name'][$i];
$Department= $_POST['Department'][$i];
$Problem= $_POST['Problem'][$i];
$Ext_no= $_POST['Ext_no'][$i];
$Ip_Add= $_POST['Ip_Add'][$i];
$Remark= $_POST['Remark'][$i];
$Email= $_POST['Email'][$i];
$status= $_POST['status'][$i];
$id = $_POST['id'][$i];
$query = "UPDATE entryform SET Name = '$Name',Department = '$Department',Problem = '$Problem',Ext_no = '$Ext_no',Ip_Add = '$Ip_Add',Remark = '$Remark',Email = '$Email',status = '$status'WHERE id = '$id' LIMIT 1";
mysql_query($query) or die ("Error in query: $query");
echo "$Name<br /><br /><em>Updated!</em><br /><br />";
++$i;
}
?>