0

hello friends i want to add confirmation box to my delete option in the pagination code so when the user want to delete the record before deleting it may as for the option yes or no...below is my code and the code in bold is the delete code....

<?php
		
		
     mysql_connect("localhost","root","")or die(mysql_error());
     mysql_select_db("project")or die(mysql_error());

	 
	   if($_GET['action']=='del' & $_GET['id']!="")
	{
		
	 mysql_query("DELETE FROM stu_info WHERE id='".$_GET['id']."'");	

	}
	 
	 $per_page = 1;


     $pages_query = mysql_query("SELECT COUNT('id') FROM `stu_info`");
    $pages = ceil(mysql_result($pages_query, 0)/$per_page);
    $page = (isset($_GET['page'])) ? (int)$_GET['page'] :1 ;
     $start = ($page-1)* $per_page;
	 
 // $search = $_GET['go'];	
    $search = $_POST['search'];
   $dropdown = $_POST['type'];
 
   



$query = mysql_query("SELECT `id`,`name`, `lastname`,`admission`,`day_list`,`month_list`,`year_list`,`gender`,`Cityy` FROM stu_info WHERE $dropdown='$search'") ;

	if($search=='' || $dropdown==''){
$query = mysql_query("SELECT `id`,`name`, `lastname`,`admission`,`day_list`,`month_list`,`year_list`,`gender`,`Cityy`  FROM `stu_info` LIMIT $start, $per_page");
	}
	  


while($query_row=mysql_fetch_assoc($query))

{
$id = $query_row['id'] ;
$ad_title = $query_row['name'] ;
$lastname = $query_row['lastname'];
$admission = $query_row['admission'];
$day = $query_row['day_list'];
$month = $query_row['month_list'];
$year = $query_row['year_list'];
$gender = $query_row['gender'];
$city = $query_row['Cityy'];


$display_block .= "

  <tr align='center'>

  <td><b><u>$id</u></b></td>
  <td>$ad_title</td>
  <td>$lastname</td>
  <td>$admission</td>
  <td>$day-$month-$year</td>
  <td>$gender</td>
  <td>$city</td>
  <td><div class='view'><a href='stuInfoEdit.php?id=$id&action=view'><img src='edit.jpg'style='height: 23px; width: 23px;'/> </a><a href='db.php?id=$id&action=view'><img src='search.jpg'style='height: 23px; width: 23px;'/> </a>[B]<a href='viewData.php?id=$id&action=del' ><img src='deletered.png'style='height: 20px; width: 20px;' /></a>[/B]
  
  </div></td>
  </tr>" ;
  
 
}
echo '</table>'; 

?>

here i have tried my own to put javascript on the delete code above

</script>

<script type="text/javascript">

function clickme(){
	
var hi = confirm("Are sure want to delete")


if( hi == true){

alert("Entry Deleted")
window.location = "<a href='viewData.php?id=$id&action=del' >";[B] [I]here i got the problem[/I][/B]
	
}else
if(hi == false){
window.location = 'http://localhost/project/student%20info/search.php';	
	
}
	
}
</script>

please i cant figure it out the part that how to put the code on the delete link please help me

Edited by extemer: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Airshow
0

You can do the whole thing in the a tag.

The secret is to return true from the tag's onclick handler to allow the href action or false to disallow. This is made easy because confirm() itself returns true or false.

<a href="viewData.php?id=$id&action=del" onclick="return confirm('Are sure want to delete?')"><img src='deletered.png' style="height: 20px; width: 20px;" /></a>

Airshow

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.