I need some help with my coding:(. I have a php file with a delete link. It flags the user record with "1" when delete is clicked. What I don't know is that "how to remove the user record from my php file". The user record is fetched from mysql and is presented in a HTML table. What i want is that when a user clicks "delete" the row is the HTML table to disappear. The php coding for the delete.php is ok. can anyone help me please. My users.php codes are below.:'(

<?php include("_include/ssi/header.php"); ?>
  <!-- TABLE CONTENTS FOR EXISTING USERS STARTS HERE -->
  <table width="870" border="0" cellspacing="1" cellpadding="1" align="center" class="data-table">
    <!--PAGINATION CODE STARTS HERE-->
    <?	//Query for Paging...
			  $str=mysql_query("select * from users order by user_Id") or die(mysql_error());
			  $totalrecord=mysql_num_rows($str);
		  
			  $pagesize=10;
			  $noofpages=$totalrecord/$pagesize;
			  if (!isset($_REQUEST['startdata']))
			  $startdata=0;
			  else
			  $startdata=$_REQUEST['startdata'];
			  $count=$startdata;
			  $strrec="select * from users order by user_Id limit ".$startdata.",".$pagesize;
		  						
					//Query for fetching admin details
		   $adm = mysql_query("SELECT admin_id, admin_forename, admin_surname, admin_username FROM admin");
				 while($admdb = mysql_fetch_array($adm)){
					$admin[''.$admdb['admin_id'].''] = array($admdb['admin_forename'],$admdb['admin_surname'],$admdb['admin_username']);	
						}
						
						//die(print_r($admin));
		  
			  $k=0;	
			  $res1=mysql_query($strrec) or die("cannot select user");
		  
		  
		  ?>
    <!--PAGINATION CODE-->
    <tr>
      <td colspan="8" class="bg">existing users</td>
    </tr>
    <tr>
      <td width="105" class="table-head" style="font-weight:bold">ID</td>
      <td width="162" class="table-head" style="font-weight:bold">Date</td>
      <td width="147" class="table-head" style="font-weight:bold">User</td>
      <td width="156" class="table-head" style="font-weight:bold">Last modified by</td>
      <td width="105" class="table-head" style="font-weight:bold">Delete</td>
      <td width="81" class="table-head" style="font-weight:bold">Edit</td>
    </tr>
    <? 
		  
			  while ($row=mysql_fetch_array($res1))   {
			  $k++;
			  $count++;
		  ?>
    <tr>
      <td><img src="images/RecordIcon.jpg" width="15" height="16" alt="User Id" /> <? echo $count ?></td>
      <td><? echo $row["user_date_created"] ?></td>
      <td><? echo $row["user_surname"], " " ,$row["user_forename"] ?></td>
      <td><? echo $admin[''.$row["user_creator"].''][0]." ".$admin[''.$row["user_creator"].''][1]; ?></td>
      <td><a href="deleteuser.php?user_Id=<? echo $row["user_Id"] ?>"><img src="images/delete.gif" width="16" height="16" alt="Delete" border="0"/></a></td>
      <td><a href="edit_user.php?user_Id=<? echo $row["user_Id"] ?> "><img src="images/edit.gif" width="16" height="16" alt="Edit" border="0"/></a></td>
    </tr>
    <?	} ?>
    <tr>
      <td colspan="8" class="bg2"></td>
    </tr>
  </table>
  </form>
  <br />
  <!--PAGINATION CODE-->
  <div align="right" class="pagination">
    <? //Query for displaying page numbers
		  if($startdata<>0) 
		  {
		  $prev=$startdata-$pagesize;
			  echo "<a href='users.php?startdata=".$prev."'><font class=bold><b>« Prev</b></a>&nbsp;&nbsp;";
		  }
		  ?>
    <font class="bold"></font>
    <?
		  for ($i=0;$i<$noofpages;$i++)
		  {
			  $pageno=$i+1;
			  $j=($pagesize*$pageno)-$pagesize;
		  
			  if ($startdata==0 && $i==0)
			  {
				  echo "<font class=bold>". $pageno."</b></span> ";
			  }
			  else
			  {
				  if($startdata == ($pagesize*($pageno))-$pagesize)
				  {
					  echo "<font class=bold>". $pageno."</font> ";
				  }
				  else
				  {
					  echo "<a href='users.php?startdata=".$j."'><font class=bold>". $pageno. "<font></a> ";
				  }
			  }
		  }
		  ?>
    </font>
    <?
		  if($startdata+$pagesize<$totalrecord)
		  {
		  $next=$startdata+$pagesize;
			  echo "&nbsp;&nbsp;<a class=prevnext href='users.php?startdata=".$next."'><font class=bold>Next »</a>";
		  }
		  ?>
  </div>
  <!--PAGINATION CODE ENDS HERE-->
  <br/>
  <!-- TABLE CONTENTS FOR EXISTING USERS ENDS HERE -->
  <?php include("_include/ssi/footer.php"); ?>

Any help will be grealty appreciated.:D

1. have a delete link next to each output. if its an href you will use GET and if a POST use a form button.

get the id of that user then just use

DELETE * FROM the_table WHERE the_record_of _the_user = '$the_variable you_acquired'

ur code is right.. on same page only wright this code.

<?php
if(isset($_GET['user_Id']))
{
$user_id=$_GET['user_Id'];
$result=mysql_query("DELETE FROM table_name WHERE user_Id=$user_id");
}
//if user id is string then use single quote marks.
//also wright this code before SELECT statement. mean on op of page.
?>

You have to delete your record from database (sending the row id by POST, GET ...) and than refresh the page.
Previous posts told you how to delete a record using mysql ...

Hi Guys...

Thanks for replying. It's just that what i need help is that the user record is fetched from mysql DB and it's presented in html table. I don't want to delete the user record from mysql. The delete function only flags the record. I have done that already. I know how to do that. But I what I want is that when the user record is flagged, the user record in my HTML table to disappear but not from DB. Basically, I want the row in my Html table to disappear.

Does anyone know how to do it?

Than select only records that do not have that flag (use WHERE clause in your query)

take another field in db say for example field is recordstatus , set the default value for recordstatus is 1 . when you click delete update recordstatus to 0. refresh the page and display the records(put where condition recordstatus=1).

Your code is embedded and the table and other html displays whether or not their is an output result. Process the delete and add an if statement to verify that there is actually data for the row. If there is, echo the data container HTML, if not omit it.

i think example may help you
<?php
$id = $_GET[id];

$q = "delete from user where id='$id'";
$r = mysql_query($q);
if($r)
header('Location:--.php');
?>

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.