xedstr
asked on
Asking confirmation before DELETE
Hi,
I use fllowing parts in my code :
CODE =>
...
if($_GET['action']=="delet e")
{ $result2 = mysql_query("DELETE FROM link WHERE QuestionNr=$id",$con);
....//and other delete actions
}
<form>
<input type=hidden name="id" value="<?php echo $id ?>">
<input type='submit' value='Delete question' name='delete' o onclick='checkBeforeDelete Question() '>
<input type="button" Name= "delete" value="Delete" onClick="
if (confirm('Do you wish to delete?'))
{this.form.action='<? $_SERVER['PHP_SELF']."?act ion=delete " ?>';this.form.submit();}">
</form>
__________________________ _
This code is not doing what I intended to do...
If I press OK in the confirm-screen => I get only redirected to the same screen without any delete.
Can anyone help me out of here? Is there a better solution (using only PHP for example)?
Thanks in advance,
EDS
I use fllowing parts in my code :
CODE =>
...
if($_GET['action']=="delet
{ $result2 = mysql_query("DELETE FROM link WHERE QuestionNr=$id",$con);
....//and other delete actions
}
<form>
<input type=hidden name="id" value="<?php echo $id ?>">
<input type='submit' value='Delete question' name='delete' o onclick='checkBeforeDelete
<input type="button" Name= "delete" value="Delete" onClick="
if (confirm('Do you wish to delete?'))
{this.form.action='<? $_SERVER['PHP_SELF']."?act
</form>
__________________________
This code is not doing what I intended to do...
If I press OK in the confirm-screen => I get only redirected to the same screen without any delete.
Can anyone help me out of here? Is there a better solution (using only PHP for example)?
Thanks in advance,
EDS
CODE =>
...
if($_GET['action']=="delet e")
{ $result2 = mysql_query("DELETE FROM link WHERE QuestionNr=$id",$con);
....//and other delete actions
}
<form name=toto method=post action="">
<input type=hidden name="id" value="<?php echo $id ?>">
<input type="button" Name= "delete" value="Delete" onClick="
if (confirm('Do you wish to delete?'))
{document.toto.action='<? $_SERVER['PHP_SELF']."?act ion=delete " ?>';document.toto.submit() ;}">
</form>
I don't think this is necessary :
<input type='submit' value='Delete question' name='delete' onclick='return checkBeforeDeleteQuestion( ),'>
...
if($_GET['action']=="delet
{ $result2 = mysql_query("DELETE FROM link WHERE QuestionNr=$id",$con);
....//and other delete actions
}
<form name=toto method=post action="">
<input type=hidden name="id" value="<?php echo $id ?>">
<input type="button" Name= "delete" value="Delete" onClick="
if (confirm('Do you wish to delete?'))
{document.toto.action='<? $_SERVER['PHP_SELF']."?act
</form>
I don't think this is necessary :
<input type='submit' value='Delete question' name='delete' onclick='return checkBeforeDeleteQuestion(
However tested your code how it is and it redirects me to same page with ?id=xxx
meaning it submits name and value from hidden
i am not great JavaScript expert but it's JavaScript error however
//bljak
meaning it submits name and value from hidden
i am not great JavaScript expert but it's JavaScript error however
//bljak
in my proposal, and althought it's considered bad practice :D, I left the $action being in $_GET and the $id in $_POST
for security and such
for security and such
ASKER
I used before the following javascript but it was not correct because, even if the user presses CANCEL, the delete is performed...
<script language="javascript" type="text/javascript">
function checkBeforeDeleteQuestion( )
{ var answer;
answer=confirm("Are you sure this question must be deleted?");
if(answer!=true)
{ return answer;
}
else
{
return false;
}
}
</script>
-----------------
So, I prefer another way to solve this problem... using php.
The first time the users enters the page : only the id-number is mentioned.
On the page, the visitor can view the information and eventualy delete the item in the database.
When he wants to delete the information, the user must receive a page that asks his confirmation. Only if confirmed, the cancel-proces may take place.
I think this must be possible to code in PHP, from 1 page. Can anyone help me to get me on track?
EDS
<script language="javascript" type="text/javascript">
function checkBeforeDeleteQuestion(
{ var answer;
answer=confirm("Are you sure this question must be deleted?");
if(answer!=true)
{ return answer;
}
else
{
return false;
}
}
</script>
-----------------
So, I prefer another way to solve this problem... using php.
The first time the users enters the page : only the id-number is mentioned.
On the page, the visitor can view the information and eventualy delete the item in the database.
When he wants to delete the information, the user must receive a page that asks his confirmation. Only if confirmed, the cancel-proces may take place.
I think this must be possible to code in PHP, from 1 page. Can anyone help me to get me on track?
EDS
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have in fact reformed completely my page and used PDP this way :
Below you will find the structure .
In the delete I ask the user for confirmation and after that he has choosen YES he gets the confirmation for the delete with possibility to go to another page.
<?php
if(isset($_GET['action']))
$action = $_GET['action'];
else
$action = '0';
switch ($action) {
case 'add':
echo "Add.";
break;
case 'edit':
echo "Edit.";
break;
case 'deleteConfirmed':
echo "DeleteConfirmed.";
break;
case 'delete':
echo "Delete.";
break;
default:
?>
<html>
<title></title>
<body>
<a href="/checkbook/index.php ?action=ad d">Add</a> <br>
<a href="/checkbook/index.php ?action=ed it">Edit</ a><br>
<a href="/checkbook/index.php ?action=de lete">Dele te</a><br>
</body>
</html>
<?php
break;
}
Below you will find the structure .
In the delete I ask the user for confirmation and after that he has choosen YES he gets the confirmation for the delete with possibility to go to another page.
<?php
if(isset($_GET['action']))
$action = $_GET['action'];
else
$action = '0';
switch ($action) {
case 'add':
echo "Add.";
break;
case 'edit':
echo "Edit.";
break;
case 'deleteConfirmed':
echo "DeleteConfirmed.";
break;
case 'delete':
echo "Delete.";
break;
default:
?>
<html>
<title></title>
<body>
<a href="/checkbook/index.php
<a href="/checkbook/index.php
<a href="/checkbook/index.php
</body>
</html>
<?php
break;
}
{this.form.action='<? $_SERVER['PHP_SELF']."?act
should be rather
{this.form.action='<? echo $_SERVER['PHP_SELF']."?act
and i am not sure about JavaScript syntax this.form.action
//bljak