Hi, I can show data from the database using query

<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$a= $_POST["SiteId"];
mysql_select_db("abc", $con);

$result = mysql_query("SELECT * FROM sitepinfo
WHERE SiteId='$a'");
echo "<table cellpadding=2 cellspacing=2 width=100% >
<tr>
<th bgcolor=#5D9BCC>SiteID</th>
<th bgcolor=#5D9BCC>Maintained By</th>

</tr>";

while($row = mysql_fetch_array($result))
  {
  

  echo "<tr>";
  echo "<td bgcolor=#FEE9A9>" . $row['SiteId'] . "</td>";
  echo "<td bgcolor=#FEE9A9>" . $row['MaintainedBy'] . "</td>";

  echo "</tr>";
  


  }
echo "</table>";


mysql_close($con);

?>

Now It shows for example 5 results , I want an Approve, Edit, and Delete button like image I Attached, please tell me how I can Show Edit, Update, and approve option with each record Shown. also Checkboxes for selection of record and then delete button in the bottom which delete only selected Records.

Thanks in advance...

Ayesha

Please tell me is it possible?

Yes.

Everything you need can be found using google. I have answered several similar questions on daniweb so make sure you search the site as well.

>How to Approve,Edit,Delete?
Here is a sample code. I have used emp table with following structure.

create table emp
  (
    eno int primary key,
    ename varchar(50),
    edate date
  )

showemp1.php

<?php
  $server="localhost";
  $user="root";
  $pass="root";
  $database="sampledb";
  
   $cmd=$_POST["cmd"];
   $eno=$_POST["eno"];
   $ename=$_POST["ename"];
   $edate=$_POST["edate"];
    
   # Connect to database
   $cn=mysql_connect($server,$user,$pass);
   if(!$cn) {
       die ("<br/>DB not connnected : " . mysql_error()); 
    }
   # Select a database	
   $db=mysql_select_db($database,$cn);
	if(!$db)
	   die(mysql_error() . "  " . mysql_errno());

 if(isset($cmd,$eno))
     {
# --- When edit button press --------
         if($cmd=="Edit") {
	  $sql="select * from emp where eno=$eno";
	  $res=mysql_query($sql);
	  $r=mysql_fetch_row($res);
print<<<TTT
<form method="post" action="showemp1.php">
<br/>No <input type="text" name="eno"  value="$r[0]"  />
<br/>Name <input type="text" name="ename" value="$r[1]"/>
<br/>Date <input type="text" name="edate" value="$r[2]"/>
<br/><input type="submit" name="cmd" value="Update"/>
<input type="submit" name="cmd" value="Cancel"/>
<hr/>
</form>     
TTT;
}
 # -- Delete a record --
  if($cmd=="Delete") {
      $sql="delete from emp where eno=$eno";
      mysql_query($sql);
     echo "Record deleted";
     }
 # -- Update a record --
  if($cmd=="Update") {
      $sql="update emp set ename='$ename',edate='$edate' where  
               eno=$eno";
      mysql_query($sql);
     echo "Record updated";
    }
}    
	   
   # -- Show the list  - Grid
	$sql="select * from emp";
	$res=mysql_query($sql,$cn);
	if(!$res)
	   die ("<br/>" . mysql_error());

	 print "<table border='1'>";
print "<tr><th>No</th><th>Name</th><th>B'Date</th><th>Action</th></tr>";		   
	 while($r=mysql_fetch_array($res))
	   {
	     print "<tr><form method='post' action='showemp1.php'>";
	     print "<td>$r[0]</td><td>$r[1]</td><td>$r[2]</td><td>";
		 print "<input type='hidden' value='$r[0]' name='eno'/>";
		 print "<input type='submit' name='cmd' value='Edit'/>";
		 		 print "<input type='submit' name='cmd' value='Delete'/>";
      print "</td></form></tr>";				 
	   }
	 print "</table>";  
      mysql_close($cn);
?>

This code is great and I really imress from your talent .
Thanks for helping me. If I want Simple text like Edit and Delete instead of button then what change I do in a code. Thank you so much.....

Do you want to use hyperlinks in place of Edit and Delete buttons?
-- You have to use javascript.

Adapost I have change this but when I press Delete it says Record Deleted but actualyy not.
In your code everything working perfectly
But now after i Edit it shows data and EDIT Delete Buttons but not working.
Please check this code.

<?php
  $server="localhost";
  $user="root";
  $pass="root";
  $database="onm";
  
   $cmd=$_POST["cmd"];
   $eno=$_POST["eno"];
   $ename=$_POST["ename"];
   $edate=$_POST["edate"];
    
   # Connect to database
   $cn=mysql_connect($server,$user,$pass);
   if(!$cn) {
       die ("<br/>DB not connnected : " . mysql_error()); 
    }
   # Select a database	
   $db=mysql_select_db($database,$cn);
	if(!$db)
	   die(mysql_error() . "  " . mysql_errno());

 if(isset($cmd,$eno))
     {
# --- When edit button press --------
         if($cmd=="Edit") {
	  
	  $res = mysql_query("SELECT * FROM Info
WHERE SiteId='$eno' ");
	  
	  $r=mysql_fetch_row($res);
print<<<TTT
<form method="post" action="editdelete.php">
<br/>No <input type="text" name="eno"  value="$r[0]"  />
<br/>Name <input type="text" name="ename" value="$r[1]"/>
<br/>Date <input type="text" name="edate" value="$r[2]"/>
<br/><input type="submit" name="cmd" value="Update"/>
<input type="submit" name="cmd" value="Cancel"/>
<hr/>
</form>     
TTT;
}
 # -- Delete a record --
  if($cmd=="Delete") {
      $sql="delete from info where SiteID=$eno";
      mysql_query($sql);
     echo "Record deleted";
     }
 # -- Update a record --
  if($cmd=="Update") {
      $sql="update info set Alias='$ename',Code='$edate' where  
               SiteID=$eno";
      mysql_query($sql);
     echo "Record updated";
    }
}    
	   
   # -- Show the list  - Grid
	$sql="select * from Info";
	$res=mysql_query($sql,$cn);
	if(!$res)
	   die ("<br/>" . mysql_error());

	 print "<table border='1'>";
print "<tr><th>SiteID</th><th>Alias</th><th>Code</th><th>Action</th></tr>";		   
	 while($r=mysql_fetch_array($res))
	   {
	     print "<tr><form method='post' action='editdelete.php'>";
	     print "<td>$r[0]</td><td>$r[1]</td><td>$r[2]</td><td>";
		 print "<input type='hidden' value='$r[0]' name='eno'/>";
		 print "<input type='submit' name='cmd' value='Edit'/>";
		 		 print "<input type='submit' name='cmd' value='Delete'/>";
      print "</td></form></tr>";				 
	   }
	 print "</table>";  
      mysql_close($cn);
?>

O yes I got it right
I have change this

$sql="update info set Alias='$ename',Code='$edate' where  
               SiteID=$eno";
      mysql_query($sql);

with this

$sql = mysql_query("update Info set Alias='$ename',Code='$edate' where  
               SiteID='$eno' ");

Thanks

Hi Adapost please check this code it does not show SiteId
I want to update like this but its not working. :( please.
My Table firlds are SiteID , Code, Long,Lat . is there any mistake in this code. It shows data in the fields and checkboxes but I laso want to show SiteId in the field which are also editable.

<strong>Update multiple rows in mysql</strong><br> 

<?php 
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="root"; // Mysql password 
$db_name="abc"; // Database name 
$tbl_name="info"; // Table name 

// Connect to server and select databse. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

$sql="SELECT * FROM $tbl_name"; 
$result=mysql_query($sql); 

// Count table rows 
$count=mysql_num_rows($result); 
?> 
<table width="500" border="0" cellspacing="1" cellpadding="0"> 
<form name="form1" method="post" action="<? echo $_SERVER['REQUEST_URI']; ?>"> 
<tr> 
<td> 
<table width="500" border="0" cellspacing="1" cellpadding="0"> 


<tr> 
<td align="center"><strong>Id</strong></td> 
<td align="center"><strong>Code</strong></td> 
<td align="center"><strong>Long</strong></td> 
<td align="center"><strong>Lat</strong></td> 
<td align="center"><strong>On / Off</strong></td> 
</tr> 
<?php 
while($rows=mysql_fetch_array($result))
{ 
?> 
<tr> 
<td align="center"><input type="text" name="name<? echo $rows['SiteID']; ?>" value="<? echo $rows['SiteID']; ?>" /></td> 
<td align="center"><input name="name<? echo $rows['SiteID']; ?>" type="text" id="name" value="<? echo $rows['Code']; ?>"></td> 
<td align="center"><input name="lastname<? echo $rows['SiteID']; ?>" type="text" id="lastname" value="<? echo $rows['Long']; ?>"></td> 
<td align="center"><input name="email<? echo $rows['SiteID']; ?>" type="text" id="email" value="<? echo $rows['Lat']; ?>"></td> 
<td align="center"><input name="ONOFF<? echo $rows['SiteID']; ?>" type="checkbox" id="ONOFF" value="1" 
<?php if ($rows['ONOFF'] ==1) { echo "checked";} else {} ?> 
></td> 
</tr> 
<?php 
} 
?> 
<tr> 
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> 
</tr> 
</table> 
</td> 
</tr> 
</form> 
</table> 
<?php 
// Check if button name "Submit" is active, do this 
if($Submit)
{ 
	foreach($_POST['SiteID'] as $SiteID)
	{ 
		$result=mysql_query("UPDATE ".$tbl_name." SET code='".$_POST["code".$SiteID]."', Long='".$_POST["Long".$SiteID]."', Lat='".$_POST["Lat".$SiteID]."', ONOFF='".$_POST["ONOFF".$SiteID]."' WHERE SiteID='".$SiteID."'"); 
		
	} 
} 

if($result1){ 
header("location:onm_n.php"); 
} 
mysql_close(); 
?>

Never try to use a code written by someone else.

<strong>Update multiple rows in mysql</strong><br> 

<?php 
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="root"; // Mysql password 
$db_name="sampledb"; // Database name 
$tbl_name="info"; // Table name 

// Connect to server and select databse. 
mysql_connect($host, $username, $password)or die("cannot connect"); 
mysql_select_db($db_name)or die("cannot select DB"); 

if(isset($_POST["cmd"]))
{ 
         $i=0;
	foreach($_POST["SiteID"] as $SiteID)
	{ 
                $sql="UPDATE info SET code='" . $_POST["Code"][$i] . "', `Long`='" . $_POST["Long"][$i] . "',Lat='" . $_POST["Lat"][$i] . "',ONOFF='" . $_POST[ONOFF][$i] . "' WHERE SiteID='$SiteID'";
                $i++;
		$result=mysql_query($sql); 
                if(!$result)
                   print $sql . "<br>" . mysql_error();
                else
                 print "<br/>$SiteID   $sql"   ;
	} 
} 

$sql="SELECT * FROM $tbl_name"; 
$result=mysql_query($sql); 

// Count table rows 
$count=mysql_num_rows($result); 

?> 
<table width="500" border="0" cellspacing="1" cellpadding="0"> 
<form name="form1" method="post" action="<? echo $_SERVER['REQUEST_URI']; ?>"> 
<tr> 
<td> 
<table width="500" border="0" cellspacing="1" cellpadding="0"> 


<tr> 
<td align="center"><strong>Id</strong></td> 
<td align="center"><strong>Code</strong></td> 
<td align="center"><strong>Long</strong></td> 
<td align="center"><strong>Lat</strong></td> 
<td align="center"><strong>On / Off</strong></td> 
</tr> 
<?php 
while($rows=mysql_fetch_array($result))
{ 
?> 
<tr> 
<td align="center"><input type="text" name="SiteID[]" value="<? echo $rows['SiteID']; ?>" /></td> 
<td align="center"><input name="Code[]" type="text" id="name" value="<? echo $rows['Code']; ?>"></td> 
<td align="center"><input name="Long[]" type="text" id="lastname" value="<? echo $rows['Long']; ?>"></td> 
<td align="center"><input name="Lat[]" type="text" id="email" value="<? echo $rows['Lat']; ?>"></td> 
<td align="center"><input name="ONOFF[]" type="checkbox" id="ONOFF" value="1" 
<?php if ($rows['ONOFF'] ==1) { echo "checked";} else {} ?> 
></td> 
</tr> 
<?php 
} 
?> 
<tr> 
<td colspan="4" align="center"><input type="submit" name="cmd" value="Submit"></td> 
</tr> 
</table> 
</td> 
</tr> 
</form> 
</table> 
<?php 
// Check if button name "Submit" is active, do this 

/*
if($result1){ 
header("location:onm_n.php"); 
} 
*/ 
mysql_close(); 
?>

I am looking for users idea approval and management system where user can register their self online and submit an idea/thought on the page and it only reflects to their reporting manager to approve.

if the manager approves the user idea then only it will go to the management(admin). or else should sent a sorry message on idea disapproval.

and management(admin) needs to have approve and dissprove access.

please help to create this in php & mysql or please share if anyone have the source code for this. would appreciate for your support.

hello sheik I need to do something similar to what you have asked for here...Did you solve it ? if so can you please share the infrustructure of the system..thanks

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.