Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从<;更新Mysql值;a href>;链接未捕获引用错误_Php_Mysql - Fatal编程技术网

Php 从<;更新Mysql值;a href>;链接未捕获引用错误

Php 从<;更新Mysql值;a href>;链接未捕获引用错误,php,mysql,Php,Mysql,我是php和mysql新手,在理解为什么数据库中更新值的特定函数不起作用时遇到问题 我希望能够在用户单击链接时将“0”int更改为“1”。(我使用值0/1跟踪用户帐户是否处于活动状态) 链接内容如下: <?php $user = query("SELECT * FROM users WHERE id = ?", $_SESSION["id"]); //check to see if the user is active or not if ($user [0][

我是php和mysql新手,在理解为什么数据库中更新值的特定函数不起作用时遇到问题

我希望能够在用户单击链接时将“0”int更改为“1”。(我使用值0/1跟踪用户帐户是否处于活动状态)

链接内容如下:

<?php

    $user = query("SELECT * FROM users WHERE id = ?", $_SESSION["id"]);

    //check to see if the user is active or not
    if ($user [0]['active'] == 0)
    {
    printf("Your account is not currently active ");
    printf('<a href="#" onclick="activate();">Click Me</a>');
    printf(" to reactivate");
    }
    //assuming they have logged in they will probably want to make themselves active

?>
function activate()
    {
    require("../templates/activate_user.php");
    exit;
    }
我在一个单独的functions.php文件中定义了activate,该文件正在加载并具有正确的权限。(我确信它是由上面的代码加载的,就像我在上面的代码中定义“手动激活”时一样,我收到一个错误,告诉我无法定义具有相同名称的两个函数)

functions.php部分内容如下:

<?php

    $user = query("SELECT * FROM users WHERE id = ?", $_SESSION["id"]);

    //check to see if the user is active or not
    if ($user [0]['active'] == 0)
    {
    printf("Your account is not currently active ");
    printf('<a href="#" onclick="activate();">Click Me</a>');
    printf(" to reactivate");
    }
    //assuming they have logged in they will probably want to make themselves active

?>
function activate()
    {
    require("../templates/activate_user.php");
    exit;
    }
最后,activate_user.php显示:

<?php
    // configuration
        require("../includes/config.php"); 

    query("UPDATE users SET active = 1 WHERE id = ?", $_SESSION["id"]);
    return false;

?>

我已经搜索了一个又一个关于如何修复这个错误的问题,但是我还没有能够修复这个问题。我猜这可能与激活的范围有关,但我不确定这是正确的路径

收到的任何帮助都很好,这是我第一次尝试使用php/mysql,所以欢迎大家提供所有帮助

谢谢,


Andy

onclick=“activate();”是Javascript代码。剩下的代码是用PHP编写的。这两种方法都不能以这种方式协同工作。

为了简化操作,我通过调用同一页面并在该页面中定义函数来解决问题:

<?php

function activate()
    {
    require("../templates/activate_user.php");
    exit;
    }

//check to see if the user is active or not
    if ($user [0]['active'] == 0)
    {
    printf("Your account is not currently active ");
    printf('<a href="index.php?action=callfunction">Click Me</a>');
    printf(" to reactivate");

    //assuming they have logged in they will probably want to make themselves active
    if(isset($_GET['action'])&& $_GET['action'] =='callfunction'){
    activate();
    }

    }
?>


不确定它是否漂亮,但它确实有效。感谢您的帮助和评论(使搜索更容易!)

您将php和js混合使用。不能直接从js调用activate()php函数。使用AJAX请求php文件。不能从JavaScript调用php函数。您可以尝试执行AJAX调用来访问该函数。另外,为什么只需要
函数activate()
中的实际函数?只需将
activate_user.php
中的代码放入function.Phantom中,functions.php中的错误也是如此吗?或者我应该使用原始a href链接中的AJAX来调用函数吗?对不起,我以前没有使用过AJAX,所以我正在努力找出哪里可以定制我的谷歌搜索。