Code: Select all
<html>
<body>
<?php
$link = mysql_connect('localhost', 'root')
or die('Could not connect: ' . mysql_error());
mysql_select_db('arda') or die('Could not select database');
$dept_ID = $_POST['dept_id'];
$dept_NAME = $_POST['dept_name'];
$man_ID = $_POST['man_id'];
$loc_ID = $_POST['loc_id'];
$emp_ID = $_POST['emp_id'];
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$email = $_POST['email'];
$p_number = $_POST['p_number'];
$h_date = $_POST['h_date'];
$j_ID = $_POST['j_id'];
$sal = $_POST['sal'];
$com_pct = $_POST['com_pct'];
$mang_ID = $_POST['mang_id'];
$deprt_ID = $_POST['deprt_id'];
echo " <P><STRONG>Departments Table </STRONG></P> ";
echo " <TABLE width=700 border=1> ";
echo " <TR> ";
echo " <TD width=75><STRONG>DEPARTMENT_ID</STRONG></TD> ";
echo " <TD width=75><STRONG>DEPARTMENT_NAME</STRONG></TD> ";
echo " <TD width=75><STRONG>MANAGER_ID</STRONG></TD> ";
echo " <TD width=75><STRONG>LOCATION_ID</STRONG></TD> ";
echo " <TD width=150> </TD> ";
echo " </TR> ";
$query = "insert into departments values ( '$dept_ID' , '$dept_NAME' , '$man_ID' , '$loc_ID' )";
mysql_query($query);
$query2 = "Select * from departments";
$result = mysql_query($query2);
while($row = mysql_fetch_row($result))
{
echo "<TR>";
echo "<TD>$row[0]</TD>";
echo "<TD>$row[1]</TD>";
echo "<TD>$row[2]</TD>";
echo "<TD>$row[3]</TD>";
echo "<TD>[<a href=update.php>update</a>][<a href=remove.php>remove</a>]</TD>";
echo "</TR>";
}
echo " </TABLE> ";
echo " <P><a href=\"insert_d.php\">insert a row into departments table </a></P><HR> ";
echo " <P><STRONG>Employees Table </STRONG></P> ";
echo " <TABLE width=1300 border=1> ";
echo " <TR> ";
echo " <TD width=80><STRONG>EMPLOYEE_ID</STRONG></TD> ";
echo " <TD width=80><STRONG>FIRST_NAME</STRONG></TD> ";
echo " <TD width=80><STRONG>LAST_NAME</STRONG></TD> ";
echo " <TD width=80><STRONG>EMAIL</STRONG></TD> ";
echo " <TD width=80><STRONG>PHONE_NUMBER</STRONG></TD> ";
echo " <TD width=80><STRONG>HIRE_DATE</STRONG></TD> ";
echo " <TD width=80><STRONG>JOB_ID</STRONG></TD> ";
echo " <TD width=80><STRONG>COMMISION_PCT</STRONG></TD> ";
echo " <TD width=80><STRONG>MANAGER_ID</STRONG></TD> ";
echo " <TD width=80><STRONG>DEPARTMENT_ID</STRONG></TD> ";
echo " <TD width=160> </TD></TR> ";
$query3 = "insert into employees values ( '$emp_ID' , '$f_name' , '$l_name' , '$email' , '$p_number' ,
'$h_date' , '$j_ID' , '$sal' , '$com_pct' , '$mang_ID' , '$deprt_ID' )";
mysql_query($query3);
$query4 = "Select * from employees";
$result2 = mysql_query($query4);
while($row2 = mysql_fetch_row($result2))
{
echo "<TR>";
echo "<TD>$row2[0]</TD>";
echo "<TD>$row2[1]</TD>";
echo "<TD>$row2[2]</TD>";
echo "<TD>$row2[3]</TD>";
echo "<TD>$row2[4]</TD>";
echo "<TD>$row2[5]</TD>";
echo "<TD>$row2[6]</TD>";
echo "<TD>$row2[7]</TD>";
echo "<TD>$row2[8]</TD>";
echo "<TD>$row2[9]</TD>";
echo "<TD>[<a href=update.php>update</a>][<a href=remove.php>remove</a>]</TD>";
echo "</TR>";
}
echo " </TABLE> ";
echo " <P><a href=\"insert_e.php\">insert a row into employees table </a></P> ";
?>
</body>
</html>i have a database with 2 tables : employees and departments. i can do the insertion every time. when i click the insert link below, i can add a row (by posting with html and adding it to the database) and return back to indexx.php again. and when i return to indexx.php, the row that i add is shown. it shows me the contents of the table everytime.
but i have a problem. i have a put two links on the right of each row, to update or remove a row. but i dont know how to do it? i mean in my code, i use :
Code: Select all
while($row = mysql_fetch_row($result))
{
echo "<TR>";
echo "<TD>$row[0]</TD>";
echo "<TD>$row[1]</TD>";
echo "<TD>$row[2]</TD>";
echo "<TD>$row[3]</TD>";
echo "<TD>[<a href=update.php>update</a>][<a href=remove.php>remove</a>]</TD>";
echo "</TR>";
}But on the right of the all rows there is this update link. When i press to one of them, how can it understand that its coming from the second row for example?
Thank you for your help...