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());

    delete query

    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><a href='viewData.php?id=$id&action=del' ><img src='deletered.png'style='height: 20px; width: 20px;' /></a>

  </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' >"; here i got the problem

}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 pyTony: fixed formatting

2
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by ddymacek
0

not sure why you are calling window.location there. what is it that you want to do. are you trying to fire php when hi == true?

0

is the php on the same page or a different file. what page are we on, where is your delete code.

0

i edited the post above to show now you can see it where is my delete query and it is redirect it on the same page...I can pop up a javascript box asking if you are sure you want to delete the record, when you click on the link. When you click ok, it deletes it and when you click cancel it goes back to the page.here is the code on which i want to apply

[B]<a href='viewData.php?id=$id&action=del' ><img src='deletered.png'style='height: 20px; width: 20px;' /></a>[/B]

if any one of you can help me do this by JS it will be my pleasure

i known my JS code is wrong because i am new to it

Edited by extemer: n/a

0

here is the js function:

function decision(message, url){
     if(confirm(message)) location.href = url;
}
// you need to change your href tag above to this:
<a href=\"javascript:decision('Are You Sure You Want To Delete?','viewData.php?id=$id&action=del');\"><img src='deletered.png'style='height: 20px; width: 20px;' /></a>
0

can you explain me the following points in the code as i an new to JS
1.why you use "\" in the link tag
2.secondly if i want to echo the specfic id i an deleting in the JS dialog box what will be the syntax for that.
3. why you use parameter message and url cant we do without the parameters

thanks in advance

Edited by extemer: n/a

0

skip the second question i ask you i done it explain me the 1 and 3 questions thanks

0

1)you are in the middle of building a variable $display_block.
That $display_block = ".....bunch of stuff, and
.... more stuff,
finally your a href line // should be quoted to contain its value
<a href="
// but this would also close your ".
So the simple answer is that the \ is escaping the " mark so when php is creating that bit of code it does not see escaped characters, so <a href\"lalala\">
was needed in this case, you can probably remove the \" and replace them with ticks ' instead, but I like full quotes when dealing with text.

2) sure change the 'message' part of your href.

<a href=\"javascript:decision('Deleting $id','viewData.php?id=$id&action=del');\"><img src='deletered.png'style='height: 20px; width: 20px;' /></a>

3) Flexibility. that simple 3 line script has the ability to allow you to put a message in a 'confirm' box or not.
It also allows you to send them to any url as defined by the calling code and is not one script specific to try to solve your exact problem of wanting to call x page and x page only.
if you don't want the message, change the first part of the 'decision' call so the inside of decision() would be ('','url-to-go-to') <-- this in essence would make the 'message' part of that blank and only disply the yes / no confirm buttons.
you can call this script 20 times on the same page and send people to 20 different urls, with 20 different messages if you like.
That's flexibility, and nice re-usable code to have.

0

if you like, pm me next time you have an issue. I'll show you the light and eventually the most awesome way to code if you wish. Peace Brother. I don't offer this to everyone, but I can teach you classes/objects and ways to handle all of your data. Something Wonderful! Came from the black obelisk's mouth. (2001) Peace!

This question has already been answered. 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.