-3

我有一个 drupal 网站,其中添加了一个允许用户删除其帐户的功能。我测试了它,当我点击按钮时,没有任何反应。我回显了值 $u['meme'] 和 $u['id'] 并且它们返回了该函数未处理的正确内容。

为什么我的查询不起作用?任何mysql设置或?谢谢!

这来自配置:

//logat = logged in

if(!isset($_SESSION['logat'])) $_SESSION['logat']='';
if($_SESSION['logat'] != '')
{
    $r=mysql_fetch_array(mysql_query("SELECT * FROM `useri` WHERE id='".$_SESSION['logat']."'"));
    $u['nume']=$r['nume'];
    $u['meme']=$r['meme'];
    $u['id']=$r['id'];
    $u['premiu']=$r['premiu'];
    $u['caracter']=$r['caracter'];
    $u['hits']=$r['hits'];
    $logat='da';
}

和有问题的代码:

<?php

function Deleteuser($logat){

mysql_query("DELETE FROM `useri` where `meme`={$u['meme']} OR `id` = {$u['id']}");
logout();
}


if($logat=='da') 
{

echo '<button onclick="Deleteuser()">Delete account</button>'; 
}
else
{
echo 'You are not logged in'; 
}
?>
4

1 回答 1

-1

这调用了一个javascript函数

echo '<button onclick="Deleteuser()">Delete account</button>'; 

并且您已经创建了 Deleteuser() php 函数,这是完全不同的事情。你可以这样做:

<?php

function Deleteuser($logat){

mysql_query("DELETE FROM `useri` where `meme`={$u['meme']} OR `id` = {$u['id']}");
logout();
}

if (isset($_POST['delete'])) {
    //call the function here to delete user
}


if($logat=='da') 
{

echo '<form action="" method="post"><input type="hidden" name="delete"><input type="submit" value="Delete account"></form>'; 
}
else
{
echo 'You are not logged in'; 
}
?>
于 2013-11-05T23:05:44.957 回答