查询不起作用,它不是从数据库中删除值

时间:2013-11-05 22:45:02

标签: php mysql

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

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

这来自configure:

//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'; 
}
?>

1 个答案:

答案 0 :(得分:-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'; 
}
?>