dongpu8935 2014-09-12 21:03
浏览 39
已采纳

调用其他函数PHP [关闭]

I have a file myfunctions.php which has four functions. all functions when called perform some transaction to database. if im calling only one function from that page that is working fine. but if im calling two functions than only one top one(function that is called first) is working and other are not working.

myfunctions.php

<?php

include('includes/db.inc.php');

function blockip($ip,$attempts){
    global $mysqli;
    if(isset($ip) && $ip!=''){
        $query = 'INSERT INTO blockip VALUES(?,?)';
        if($stmt = $mysqli -> prepare($query)){
            $stmt -> bind_param('si',$ip,$attempts);
            $stmt -> execute();
            $stmt -> close();
        }
        $mysqli -> close();
    }else{
        echo $mysqli-> error();
    }
}
function getip($ip){
    global $mysqli;
    $ip_found =  null;
    if(isset($ip) && $ip!=''){
        $query = 'SELECT `ip` FROM `blockip` WHERE `ip`=?';
        if($stmt=$mysqli -> prepare($query)){
            $stmt -> bind_param('s',$ip);
            $stmt -> execute();
            $stmt -> bind_result($ipret);
            $stmt -> fetch();
            $stmt -> close();
            if($ipret!=null)
                $ip_found = $ipret;
            else
                $ip_fount = '';
        }
        $mysqli -> close();
    }
    return $ip_found;
}
?>

other functions at this file are also using $mysqli by declaring it global and all are of similar nature.

file at which im calling these functions login.php

<?php
session_start();
include('myfunctions.php');
$client_ip = $_SERVER['REMOTE_ADDR'];
?>

<!DOCTYPE html>
<html>
     <!-- Some HTML Code HERE -->
</html>
<?php
if($_SESSION['errorcode']==1){
    echo '<center> Invalid Captcha </center>';
}elseif($_SESSION['errorcode']==2){
    echo '<center> Invalid UserName / Password Combination </center>';
    trygetip($client_ip);
}
if($_SESSION['errorcode']==3){
    session_destroy();
    header('Location: 403.html');
    exit();
}
?>

my database file db.inc.php

<?php
error_reporting(0);
$db="xxxxxx";
$host="xxxxxx";
$username="xxxx";
$password="xxxx";
$mysqli =  new mysqli($host,$username,$password,$db);
if($mysqli->connect_error){
    die('Connection Failed : '.$mysqli-> connect_errno.' : '.$mysqli -> connect_error);
}
?>

now if i use two functions getip($someiphere) and than bockip($someiphere,$attempts) than 2nd one is not working and same issue with if i replace their position. thanx in advance

  • 写回答

2条回答 默认 最新

  • douxi3554 2014-09-12 21:06
    关注

    You close the mysql connection in both functions, just omit the $mysqli -> close();.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#单片机#的问题:Lora通讯模块hc-14电路图求内部原理图
  • ¥50 esp32 wroom 32e 芯片解锁
  • ¥15 bywave配置文件写入失败
  • ¥20 基于Simulink的ZPW2000轨道电路仿真
  • ¥15 pycharm找不到在环境装好的opencv-python
  • ¥15 在不同的执行界面调用同一个页面
  • ¥20 基于51单片机的数字频率计
  • ¥50 M3T长焦相机如何标定以及正射影像拼接问题
  • ¥15 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)
  • ¥15 Mabatis查询数据