PHP: Delete from a Database with some prompts from javascript - Stack Overflow

My code is below, I am trying to delete records from mysql database but before deleting the browser has

My code is below, I am trying to delete records from mysql database but before deleting the browser has to prompt the user whether the deletion should continue. My problem is my logic is not working its deleting the record no matter what. Any help will be appreciated.

   if (isset($_POST['outofqcellchat'])){
?>
<script type ="text/javascript">
var question = confirm("Are you sure you want to unsubscribe\nThis will delete all your facebook information in QCell Facebook");
if(question){
<?php
$delusr = mysql_query("delete  from `chat_config` where `phone` = '$phonenumb'");
$row = mysql_num_rows($delusr);
if($row>=1){
header("Location:");
}
?>
alert("Unsubscribed, You can register again any time you wish\nThank You");
}else {
alert("Thanks for choosing not to unregister \nQCell Expand your world");
}
</script>
<?php
}
?>

Thats my code. Please help

My code is below, I am trying to delete records from mysql database but before deleting the browser has to prompt the user whether the deletion should continue. My problem is my logic is not working its deleting the record no matter what. Any help will be appreciated.

   if (isset($_POST['outofqcellchat'])){
?>
<script type ="text/javascript">
var question = confirm("Are you sure you want to unsubscribe\nThis will delete all your facebook information in QCell Facebook");
if(question){
<?php
$delusr = mysql_query("delete  from `chat_config` where `phone` = '$phonenumb'");
$row = mysql_num_rows($delusr);
if($row>=1){
header("Location:http://apps.facebook./qcellchat");
}
?>
alert("Unsubscribed, You can register again any time you wish\nThank You");
}else {
alert("Thanks for choosing not to unregister \nQCell Expand your world");
}
</script>
<?php
}
?>

Thats my code. Please help

Share Improve this question edited Oct 11, 2010 at 10:31 Pekka 450k148 gold badges987 silver badges1.1k bronze badges asked Oct 11, 2010 at 10:30 Sheriffo CeesaySheriffo Ceesay 111 silver badge2 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

you want to prompt the user upon click of a anchor tag or button. For eg using anchor tag

<a href="delete.php" onclick="return javascript:confirm("Are you sure you want to delete?");" />Delete</a>

This will prompt user.

Or you might use a javascript function such as

    <a href="delete.php" onclick="return check();" />Delete</a>

    <script type="text/javascript">
    function check(){
    var question = confirm("Are you sure?");
    if(question){

    return true;

    }else{

    alert("Thanks for not choosing to delete");
    return false;

    }

    }
</script>

Hope this helps.

You have a fundamental misunderstanding between PHP and Javascript here. The PHP code will be executed regardless of any JavaScript conditions (which will be processed long after PHP is done, in the browser).

You will need to change the logic so that confirming the deletion redirects the user to a PHP page that deletes the record, or starts an Ajax request with the same effect.

The PHP runs on the server before the client even sees the JavaScript. Use AJAX or a form submission instead.

Try to separate your PHP from javascript and do not forget to delete using the exact link u are targeting ,if you want to delete one by one record , in href that is where u put that Id first .

Delete

<script type="text/javascript">
function check(){
var question = confirm("Are you sure?");
if(question){

return true;

}else{

alert("Thanks for not choosing to delete");
return false;

}

}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745309115a4621894.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信