Anyone knows how to code in this:
when i delete a particular record,it display first " Are you sure, you want to delete?<br>Yes, No" all i know is in Vb but i dont know in php..i know if-else statement are present in that code..tnx in advance!

No way to do it in PHP.
VB or JS are at client side, PHP only server side. Anyway you can create a page in php with such task using HTML forms...

Member Avatar for diafol

You'd be better off with js - or ajax.

You need the js 'confirm' popup. This can be linked 'ajaxibly' to a php file which could delete file/db record, whatever, in the background and then refresh your displayed list of records/files - all without the need for whole page refresh.

If you decide to delve into ajax, you'll do well to look at a js library/framework: jquery and prototype are good places to start - this allows easy access to the 'ajax response'.

Another way of doing this I saw the other day (can't remember where) was that a check box with a label 'Check to confirm delete' and a submit button appeared next to the item to be deleted - I assume this was done via js '.append'. Nice and refreshing change from a popup.

You'd be better off with js - or ajax.

You need the js 'confirm' popup. This can be linked 'ajaxibly' to a php file which could delete file/db record, whatever, in the background and then refresh your displayed list of records/files - all without the need for whole page refresh.

If you decide to delve into ajax, you'll do well to look at a js library/framework: jquery and prototype are good places to start - this allows easy access to the 'ajax response'.

Another way of doing this I saw the other day (can't remember where) was that a check box with a label 'Check to confirm delete' and a submit button appeared next to the item to be deleted - I assume this was done via js '.append'. Nice and refreshing change from a popup.

so what's the code for that?

Member Avatar for diafol

so what's the code for that?

For what? Which bit?

For what? Which bit?

in doing a pop up question when deleting a record..just like in VbQuestion..

<a href="javascript:del('<?=$p_row['p_id_pk']?>)">delete</a>
<script type="text/javascript">
function del(x)
{
if(confirm("Do You Really want to delete this product"))
{
document.form.action="product.php?delid="+x;
document.form.submit();
}
}
</script>

and in php

mysql_query("delete from table where id='".$_GET['delid']."'")

ok takeshi you know the drill replace database table that suites your needs.

Tried and tested

<?php

mysql_connect('localhost','root','');
mysql_select_db('joe');

?>
<?php

if(isset($_GET['btndelete'])){
$account = $_GET['account'];
if(isset($account)){
foreach($account as $val){
mysql_query( "DELETE FROM account WHERE account_id='".$val."'" );
}
}
}

?>


<html>
<head>
<title>
confirm
</title>
<script>
function deleterec(){
if(confirm("Are you sure you want to delete?")){
return true;
}else{
return false;
}
}
</script>
</head>
<body>
<form name='frm' method='get' onsubmit='return deleterec()'>
<table border='1'>
<tr>
<td>check</td><td>name</td><td>age</td>
</tr>
<?php
$sql = mysql_query( "SELECT * FROM account" );
while($row=mysql_fetch_array($sql)){
echo "<tr>
<td>
<input type='checkbox' name='account[]' value='".$row['account_id']."'></td><td>".$row['name']."<td>".$row['email']."</td>
</tr>";
}
?>
</table>
<input type='submit' name='btndelete' value='delete' />
</form>
</body>
</html>

please marked this thread solved if you think it's been solved... thanks.

Member Avatar for diafol

I always get a bit twitchy when people use simple get vars for database manipulations. This is open to abuse (yeah, yeah, so is post, I know). If you use get, I'd suggest using a confirm hash to go with the id of the record to delete.

e.g. deleterecord.php?id=3&confirm=syhnY729H6jYu27R5gjuU81b (32 chars long for an md5 hash)

Just set up a salted hash to check on querystring arrival:

if(isset($_GET['id']) && isset($_GET['confirm']) && $_GET['confirm'] == md5('mysaltysalt' . $_GET['id'] . 'myothersaltysalt')) {
  //delete the record if it exists
}else{
  //something really wrong here - somebody trying to delete your records programmatically??
}

yeah im totally aware of that, but im just using simple example here for easy understanding.

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.