最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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;

}

}

发布评论

评论列表(0)

  1. 暂无评论