I am trying to print data from dataBASE with SQL and PHP. all worked fine the issue is when I am trying to to warp all thing to function it not working and the table is not showing.
with out the function loadClient it work fine.
please help...
$("#loadbtn").click(function(){
var s = '
<?php
loadClients()
function loadClients(){
$link = mysql_connect($db_host,$db_user,$db_pass);
if(!$link) die ('Could not connect to database: '.mysql_error());
mysql_select_db($db_name,$link);
mysql_query("SET NAMES 'utf8'");
echo '<table id="clienttable" border="1" cellspacing="0" cellpadding="0" width="100%">';
echo '<tr>';
echo '<td width="80px">שם פרטי</td>';
echo '<td>שם משפחה</td>';
echo '<td>טלפון</td>';
echo '<td>אימייל</td>';
echo '<td>עיר</td>';
echo '<td width="120px">שעת רישום</td>';
echo '<td>מספרי תמונות</td>';
echo '<td>שמור</td>';
echo '</tr>';
$loadQuery="SELECT * FROM `claients` WHERE `eventreg_pictures` is null";
$result=mysql_query($loadQuery);
while($row= mysql_fetch_array($result)){
$client= $row;
$clients[]=$client;
echo '<tr>';
echo '<form id="loadForm" method="post" action="admin.php">';
echo '<td><input type="text" id="lfname" name="lfname" value="'.$client[1].'"/></td>';
echo '<td><input type="text" id="llname" name="llname" value="'.$client[2].'"/></td>';
echo '<td><input type="text" id="lphone" name="lphone" value="'.$client[3].'"/></td>';
echo '<td><input type="text" id="lemail" name="lemail" value="'.$client[4].'"/></td>';
echo '<td><input type="text" id="lcity" name="lcity" value="'.$client[5].'"/></td>';
echo '<td>'.$client[7].' ';
echo '<td><input type="text" id="lphotos" name="lphotos"/></td>';
echo '<td><input type="submit" id="savebtn" name="savebtn" value-"שמור"/></td>';
echo '</form>';
echo '</tr>';
}
echo '</table>';
}
?>';
You should use $.ajax() like
Javascript
$("#loadbtn").click(function(){
$.ajax({
type: "POST",
url: 'page.php',
success: function(d){alert(d);},
});
});
PHP
$link = mysql_connect($db_host,$db_user,$db_pass);
if(!$link) die ('Could not connect to database: '.mysql_error());
mysql_select_db($db_name,$link);
mysql_query("SET NAMES 'utf8'");
echo '<table id="clienttable" border="1" cellspacing="0" cellpadding="0" width="100%">';
echo '<tr>';
echo '<td width="80px">שם פרטי</td>';
echo '<td>שם משפחה</td>';
echo '<td>טלפון</td>';
echo '<td>אימייל</td>';
echo '<td>עיר</td>';
echo '<td width="120px">שעת רישום</td>';
echo '<td>מספרי תמונות</td>';
echo '<td>שמור</td>';
echo '</tr>';
$loadQuery="SELECT * FROM `claients` WHERE `eventreg_pictures` is null";
$result=mysql_query($loadQuery);
while($row= mysql_fetch_array($result)){
$client= $row;
$clients[]=$client;
echo '<tr>';
echo '<form id="loadForm" method="post" action="admin.php">';
echo '<td><input type="text" id="lfname" name="lfname" value="'.$client[1].'"/></td>';
echo '<td><input type="text" id="llname" name="llname" value="'.$client[2].'"/></td>';
echo '<td><input type="text" id="lphone" name="lphone" value="'.$client[3].'"/></td>';
echo '<td><input type="text" id="lemail" name="lemail" value="'.$client[4].'"/></td>';
echo '<td><input type="text" id="lcity" name="lcity" value="'.$client[5].'"/></td>';
echo '<td>'.$client[7].' ';
echo '<td><input type="text" id="lphotos" name="lphotos"/></td>';
echo '<td><input type="submit" id="savebtn" name="savebtn" value-"שמור"/></td>';
echo '</form>';
echo '</tr>';
}
echo '</table>';
}
Related
so i have a form with like 6 fields(FirstName,LastName,etc),when the users submit the form,the values are saved in a database.In another page i have a table which shows those values from database,with same 6 cols + another one which contains 2 buttons(delete and edit),the delete one works perfect,but the edit buttons has some issues
The buttons code is this:
echo '<td>';
echo '<button>Modifica!</button>';
echo '<button>Sterge!</button>';
echo '</td>';
As you can see i have assigned rand id(this is the primary key for databse rows) to the var idang.
$idang=$_GET['idang'];
if(isset($idang)) {
$CerereSQL="SELECT * FROM `angajati` WHERE id='$idang'";
$rezultat=mysqli_query($con,$CerereSQL);
$rand=mysqli_fetch_assoc($rezultat);
I've made another variable with the global var $_GET['idang'],and then i have SELECTED the table angajati from database where the primary key from my db its equal with the primary key from the table row,which i've pushed the edit button.This method works for the delete button,and probably for the edit one too,but the real problem is that when i want to edit that row,it will link me to another page containing another form,with original values in the fields,and when i modify those fields with other values,it must change only that row,not the entire table,or the column.But i have no idea how to do that,except that it can be done with the UPDATE statement
The rest of the code,containing the form is:
echo '<table border=0 align=center cellspacing=10>';
echo '<form action="" method=post>';
echo '<tr>';
echo '<th>Nume:</th><td><input type="text" name=nume value="';
echo $num;
echo '"></td>';
echo '<td style=color:red>';
echo $err_nume;
echo $err_nume1;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th>Prenume:</th><td><input type="text" name=prenume value="';
for($value=1;$value<count($nume);$value++) {
$c=$c."".$nume[$value];
}
echo $c;
echo '"></td>';
echo '<td style=color:red>';
echo $err_prenume;
echo $err_prenume1;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th>CNP:</th><td><input type="text" name=cnp value="';
echo $cnp;
echo '"></td>';
echo '<td style=color:red>';
echo $err_cnp;
echo $err_cnp1;
echo $err_cnp2;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th>Data angajare:</th><td><input type="text" name=data value="';
echo $rand['data'];
echo '"></td>';
echo '<td style=color:red>';
echo $err_data;
echo '</td>';
echo '</tr>';
$companii=array("S.C. 2K Telecom S.R.L.", "S.C. Accessnet International S.R.L.", "S.C. Ad Net Market Media S.A.", "S.C. Idilis S.R.L.", "S.C. Infratel Net S.R.L.");
echo '<tr>';
echo '<th>Compania:</th>';
echo '<td>';
echo '<select name=companie>';
//echo '<option value="alege">Alege compania</option>';
//if(!isset($_POST['companie'])){
echo '<option value='.$companie.'>'.$companie.'</option>';
$key=array_search($companie, $companii);
unset($companii[$key]);
//}
foreach($companii as $firme) {
echo '<option value="'.$rand['companie'].'"';
if(isset($_POST['companie']) && $_POST['companie'] == $firme) {echo " selected";}
echo ">$firme</option>";
}
echo '</select>';
echo '</td>';
echo '<td style=color:red>';
echo $err_companie;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th>Functia:</th><td><input type="text" name=functie value="';
echo $rand['functie'];
echo '"></td>';
echo '<td style=color:red>';
echo $err_functie;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td align=center><a href=tabel.php><input type=button name=button value=Inapoi!></a></td>';
echo '<td align=center><input type=submit name=submit value=Introducere! ></td>';
echo '<td align=center><input type=reset name=reset value=Resetare! ></td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2" align=center>'.$up.'</td>';
echo '</tr>';
echo '</form>';
echo '</table>';
So this form contains the old values from the table row i've pressed the button,and i want to cahnge with new values.Any idea?
Here is basic example to update name column of your table. Get other fields and add in the query.
if(isset($_POST['submit'])) {
//echo "<pre>";print_r($_POST);exit; // to check your post data
$name = $_POST['nume'];
$query = "UPDATE table_name set name='$name' where id=$idang";
mysqli_query($query); //run the query
}
echo '<form action="abc.php" method=post>'; // add action
abc.php
If($_POST)
{
// fetch values from post
// update query
}
in else you can do if $_GET then insert.
I think from this you will get an idea to solve.
http://i.stack.imgur.com/TyC6U.png
I have something like this and when a person checked a checkbox and then click the button Save, it would save the checked box and the next time the person see this table it would appear the table with all the checkboxs that the person checked or unchecked last time. How can I do that?
The months are in one array, check my code:
<?php
$results = mysql_query("SELECT * FROM utilizadores");
$month = array("January","February","March","April","May","June","July","August","September","October","November","December");
echo '<form id="form" method="post" action="">';
echo '<table border="1" align="center">';
echo '<tr class="d0">';
echo '<td align="center" height="30" width="400"><strong>Nome</strong></td>';
for($i=0;$i<=11;$i++)
{
echo '<td align="center" width="80"><strong>'.#$month[$i].'</strong></td>';
}
echo '</tr>';
$rowColors = Array('#ffffff','#ffffcc'); $c= 0;
while($row = mysql_fetch_array($results)) {
echo '<tr style="background-color:'.$rowColors[$c++ % count($rowColors)].';">';
echo '<td align="center" height="30" width="400">' . $row['nome'] . "</td>";
for($i=0;$i<=11;$i++) {
echo '<td align="center" width="80"><input type="checkbox" name="asd" /></td>';
}
}
echo "</tr>";
echo "</table>";
echo "<br>";
echo '<input name="submit" type="submit" value="Save" />';
echo '</form>';
?>
<br />
</body>
</html>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
This code works and is fine, but I was wondering if there was an easier way to code something like this?
<?php
while($rows=mysql_fetch_array($result)){
$pid=$rows['id'];
$d = $rows['date'];
echo '<style>tr, td {border:0;} #dat{text-align:right;} #co {background-color:#33B533;} </style>';
echo '<div id="postd">';
echo '<table id="mdata">';
echo '<tr>';
echo '<td>';
echo '<a href="profile.php?name=';
echo $rows['name'];
echo '">' . $rows["name"] . '</a>';
echo '</td>';
echo '<td id="dat">';
echo $result7 = nicetime($d);
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo $rows['post'];
echo '</td>';
echo '<td id="dat">';
echo '<form method="post" action="delete.php">';
echo '<input type="hidden" value="';
echo $rows['id'] . '" name="id" />';
echo '<input id="sub" type="submit" name="delete" value="Delete" />';
echo '</form>';
echo '<form method="post" action="edit.php">';
echo '<input type="hidden" value="';
echo $rows['id'] . '" name="id" />';
echo '<input id="sub" type="submit" name="edit" value="Edit" />';
echo '</form>';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
$sql9 = "SELECT * FROM `like` WHERE postid='$pid' AND userid='$userid'";
$result9=mysql_query($sql9);
if($result9){
echo '<form method="post" action="like.php">';
echo '<input type="hidden" value="';
echo $rows['id'] . '" name="id" />';
echo '<input type="hidden" value="';
echo $userid . '" name="nid" />';
echo '<input id="sub" type="submit" name="like" value="Like" />';
echo '</form>';
}
echo '</td>';
echo '<td id="dat">';
if ($rows['like'] == 1) {
echo $rows['like'] . " Like";
} else if ($rows['like'] == 0) {
echo "";
} else {
echo $rows['like'] . " Likes";
}
echo '</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
$sql2="SELECT * FROM comments WHERE postid='$pid' ORDER BY date ASC";
$result2=mysql_query($sql2);
while($rows2=mysql_fetch_array($result2)){
$c = $rows2['date'];
echo '<table id="co" border="1px solid black" width="250px" align="center">';
echo '<tr>';
echo '<td>';
echo $rows2['name'];
echo '</td>';
echo '<td id="dat">';
echo $result4 = nicetime($c);
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo $rows2['comment'];
echo '</td>';
echo '</tr>';
echo '</table>';
}
echo '<form action="addcomment.php" method="post">';
echo '<table id="co" border="1px solid black" width="250px" align="center">';
echo '<tr>';
echo '<td>';
echo '<textarea id="target" type="text" name="com" placeholder="Comment"></textarea>';
echo '</td>';
echo '<td>';
echo '<input type="submit" name="submit" value="Post">';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '<input type="hidden" value="';
echo $rows['id'] . '" name="id" />';
echo '<input type="hidden" name="name" value="Jon" />';
echo '</form>';
echo '<br/>';
}
?>
Basically I've created a Facebook type system. This spools the posts down in the order they are posted in the database. Check it out at http://bockhorst.comeze.com/Wall/wall.php Its still a work in progress. Also does anyone know a php compressor?
The more efficient way to do this is to use a proper development framework that provides some structure and cohesion to your code. What you have here is a stew of SQL, HTML, and code. It's extremely hard to maintain an application written like this.
Additionally you're using the woefully out of date mysql_query interface. Please, don't. It's terrible. You really should be using an ORM to handle your routine database interfacing, something like Doctrine or Propel. These make it easier to compose the queries correctly and deal with the data instead of being stuck trying to render all your application logic directly in SQL.
If you're dead-set on doing SQL by hand, PDO is the way to go.
I've been looking through many threads on here without finding a solution to my problem.
I've created a form that is supposed to show content of a database in input boxes, and when i change the content, it should be updated in the database.
No errors, nothing gets changed.
<?php
$con=mysqli_connect("localhost","root","","frontpage");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM frontpage_left_links")
or die("Error: ".mysqli_error($con));
while($row = mysqli_fetch_array($result)){
echo '<form action="" method="post">';
echo '<div style="float:left">';
echo '<table border="1" bordercolor="#000000">';
echo '<tr>';
echo '<td>link</td>';
echo '<td><input type="text" name="linkid" value="'.$row['link'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>img</td>';
echo '<td><input type="text" name="imgid" value="'.$row['img'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>tekst</td>';
echo '<td><input type="text" name="imgid" value="'.$row['name'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" id="update" name="gem" value="Gem"</td></td>';
echo '<td><input type="hidden" name="id" value="'.$row['id'].'"></td>';
echo '</tr>';
echo '</table></div>';
echo '<div style="float:left"><center><img src="img/'.$row['img'].'"><br />'.$row['name'].'</center></div>';
echo '</form><br /><br /><br /><br /><br /><br /><br /><br />';
}
if(isset($_POST['update'])){
$id = $_POST['id'];
$link = $_POST['linkid'];
$img = $_POST['imgid'];
$name = $_POST['nameid'];
$sql = mysqli_query("UPDATE frontpage_left_links SET link = '$link', img = '$img', name = '$name' WHERE id = '$id'");
$retval = mysqli_query( $sql, $con );
if(! $retval ){
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
}
mysqli_close($con);
?>
The form show the database content fine, but nothing happens when changed.
I appreciate any help I can get.
This is what it looks like now.
<?php
$con=mysqli_connect("localhost","root","","frontpage");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST['gem']))
{
$id = $_POST['id'];
$link = $_POST['linkid'];
$img = $_POST['imgid'];
$name = $_POST['nameid'];
$sql = mysqli_query("UPDATE frontpage_left_links SET link = '$link', img = '$img', name = '$name' WHERE id = '$id'");
$retval = mysqli_query( $con, $sql );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
}
$result = mysqli_query($con,"SELECT * FROM frontpage_left_links")
or die("Error: ".mysqli_error($con));
while($row = mysqli_fetch_array($result))
{
echo '<form action="" method="post">';
echo '<div style="float:left">';
echo '<table border="1" bordercolor="#000000">';
echo '<tr>';
echo '<td>link</td>';
echo '<td><input type="text" name="linkid" value="'.$row['link'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>img</td>';
echo '<td><input type="text" name="imgid" value="'.$row['img'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>tekst</td>';
echo '<td><input type="text" name="nameid" value="'.$row['name'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" id="update" name="gem" value="Gem"</td></td>';
echo '<td><input type="hidden" name="id" value="'.$row['id'].'"></td>';
echo '</tr>';
echo '</table></div>';
echo '<div style="float:left"><center><img src="img/'.$row['img'].'"><br />'.$row['name'].'</center></div>';
echo '</form><br /><br /><br /><br /><br /><br /><br /><br />';
}
mysqli_close($con);
?>
Now i get this error.
Warning: mysqli_query() expects at least 2 parameters, 1 given in /Applications/XAMPP/xamppfiles/htdocs/page/admin.php on line 17
Warning: mysqli_query(): Empty query in /Applications/XAMPP/xamppfiles/htdocs/page/admin.php on line 19
Could not update data:
Because your udate is at the end of the page put it above the rest.
And also change isset($_POST['update'] to isset($_POST['gem']
<?php
$con=mysqli_connect("localhost","root","","frontpage");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST['gem']))
{
$id = $_POST['id'];
$link = $_POST['linkid'];
$img = $_POST['imgid'];
$name = $_POST['nameid'];
$sql = "UPDATE frontpage_left_links SET link = '$link', img = '$img', name = '$name' WHERE id = '$id'";
$retval = mysqli_query($con,$sql );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
}
$result = mysqli_query($con,"SELECT * FROM frontpage_left_links")
or die("Error: ".mysqli_error($con));
while($row = mysqli_fetch_array($result))
{
echo '<form action="" method="post">';
echo '<div style="float:left">';
echo '<table border="1" bordercolor="#000000">';
echo '<tr>';
echo '<td>link</td>';
echo '<td><input type="text" name="linkid" value="'.$row['link'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>img</td>';
echo '<td><input type="text" name="imgid" value="'.$row['img'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>tekst</td>';
echo '<td><input type="text" name="imgid" value="'.$row['name'].'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" id="update" name="gem" value="Gem"</td></td>';
echo '<td><input type="hidden" name="id" value="'.$row['id'].'"></td>';
echo '</tr>';
echo '</table></div>';
echo '<div style="float:left"><center><img src="img/'.$row['img'].'"><br />'.$row['name'].'</center></div>';
echo '</form><br /><br /><br /><br /><br /><br /><br /><br />';
}
mysqli_close($con);
?>
try to replace :
echo '<td><input type="submit" id="update" name="gem" value="Gem"</td></td>';
with :
echo '<td><input type="submit" id="update" name="update" value="Gem"</td></td>';
In your form you are having update button name as gem but you are using if(isset($_POST['update'])) to run update query.
Change it to if(isset($_POST['gem']))
The easiest way would be to simply change the name attribute on your submit to the $_POST[] variable you used. name="update"The easiest way would be to simply change the name attribute on your submit to the $_POST[] variable you used. name="update"
Edit :: Answered already.
echo '<td><input type="submit" id="update" name="update" value="Gem"</td></td>';
Just delete the second td from above!!!
I've written a script to post information into my database for I can't get it to post and need help pointing out what I'm missing.
my php post for looks like this:
$query = "SELECT * from departments";
$res = mysql_query($query);
echo '<div id="department" >';
echo '<form action="depedit.php" method="post">';
echo '<input type="text" placeholder="Search departments">';
echo '<br>';
echo '</form>';
echo '</div>';
echo '<div id="depadd">';
echo '<form>';
echo '<table width="0" border="0">';
echo '<tr>';
echo '<td>Name:</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo "<select name='depid'>";
while ($row = mysql_fetch_array($res)) {
echo "<option value='".$row['id']."'>".$row['depname']."</option>";
}
echo "</select>";
echo '</td>';
echo ' </tr>';
echo '<tr>';
echo '<td> </td>';
echo '</tr>';
echo ' <tr>';
echo '<td><label class="limit">Select Limit for active courses in Learning Locker:</label></td>';
echo ' </tr>';
echo ' <tr>';
echo '<td>';
echo "<select name='courselimit'>";
echo "<option value='1'>1</option>";
echo "<option value='2'>2</option>";
echo "<option value='3'>3</option>";
echo "<option value='4'>4</option>";
echo "<option value='5'>5</option>";
echo "<option value='0'>Unlimited</option>";
echo "</select>";
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td> </td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="radio" id="1" name="senabled" value="1"/><label for="c1" class="required">Required<br>(Study Shredder Feature Enabled)</br></label></td>';
echo '<td><input type="radio" id="0" name="senabled" value="0"/><label for="c1" class="optional">Optional</label></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="orgid" value="'.$adminorgid.'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="createdby" value="'.$userid.'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="hidden" name="timecreated" value="'.time(now).'"></td>';
echo '</tr>';
echo '<tr>';
echo '<td> </td>';
echo '</tr>';
echo ' <tr>';
echo ' <td><button type="submit" class="btn">Submit</button></td>';
echo ' </tr>';
echo '</table>';
echo "</form>";
echo '</div>';
depedit.php looks like this:
$adddep = "INSERT INTO organization_dep (orgid,depid,courselimit,senabled,createdby,timecreated) VALUES ('".$_POST["orgid"].",".$_POST["depid"].",".$_POST["courselimit"].",".$_POST["senabled"].",".$_POST["createdby"].",".$_POST["timecreated"]."')";
$res = mysql_query($adddep);
if ($res === TRUE) {
echo "Department added successfully";
} else{
printf("Could not create department");
}
the correct information seems like its getting passed as the url displays the following information in it:
/index.php?depid=6&courselimit=3&senabled=1&orgid=9&createdby=1129&timecreated=1364005206
any help with this would be greatly appreciated as I'm sure its something simple that I'm just over looking.
You want to get the values from the $_POST
('".$_POST["orgid"].",".$_POST["depid"].",".$_POST["courselimit"].",".$_POST["senabled"].",".$_POST["createdby"].",".$_POST["timecreated"]."')";
but your saying it is passed through the URL, this looks like you need to use $_GET to get the values
--- and one small tip you can use echo to print multiple lines it works. as long as you close it, in the end
e.g
echo " <html>
<body>
</body>
</html>
";
I think you have a bunch of things to get right before this will be working:
Only the first form, which seems to be for searching departments, have method and action attributes
Since the second form does not have the action attribute, it is not submitting to depedit.php but to the same page that has the form.
Since the second form does not have the method attribute, it defaults to GET, and you are trying to read out POST variables in your PHP. If it was not using GET, you would not see those params in the resulting URL.
In your SQL insert statement, you must have single quotes around every single text value but not around int values. Now you have one single quote before the first value and one before the last which makes no sense.
First: this portion will not be POSTed "depedit.php" because there is no submit
echo '<form action="depedit.php" method="post">';
echo '<input type="text" placeholder="Search departments">';
echo '<br>';
echo '</form>';
Second: this will never be POSTed to depedit.php, since your <form> does not have an action specifying "depedit.php"
echo '<form>';
echo '<table width="0" border="0">';
echo '<tr>';
//other codes
echo "</form>";
maybe you mean to remove the first echo '</form>'(line 7) and the second <form>(line 10)