我有一个PHP函数调用的新手问题。文件:
<?php
session_start();
include("../conexionbbdd.php");
include("../conexionapi.php");
$id = $_SESSION['id'];
$inclass = $_SESSION['inclass'];
if($_SESSION['estado'] == 'activo'){
if($inclass==='1'){
checkCost();
}
else{
sendMessage();
}
function checkCost(){
//DO WHATEVER
}
function sendMessage(){
//DO WHATEVER
}
}else{
header('location:../login.php');
}
?>
控制台出现错误 (!)致命错误:在第14行的C:\ wamp \ www [removedbyme] \ actions \ msg_newMessage.php中调用未定义的函数checkCost() < /强>
答案 0 :(得分:1)
试试这个:
session_start();
include("../conexionbbdd.php");
include("../conexionapi.php");
function checkCost(){
//DO WHATEVER
}
function sendMessage(){
//DO WHATEVER
}
$id = $_SESSION['id'];
$inclass = $_SESSION['inclass'];
if($_SESSION['estado'] == 'activo'){
if($inclass==='1'){
checkCost();
}
else{
sendMessage();
}
}else{
header('location:../login.php');
}
答案 1 :(得分:0)
从上到下读取PHP代码,因此当您调用checkCost时,php不知道checkCost存在:
<?php
session_start();
include("../conexionbbdd.php");
include("../conexionapi.php");
function checkCost(){
//DO WHATEVER
}
function sendMessage(){
//DO WHATEVER
}
$id = $_SESSION['id'];
$inclass = $_SESSION['inclass'];
if($_SESSION['estado'] == 'activo'){
if($inclass==='1'){
checkCost();
}
else{
sendMessage();
}
}else{
header('location:../login.php');
}
?>