我没有重新声明时无法重新声明功能名称

时间:2013-10-27 14:02:24

标签: php function

我收到以下错误:

Fatal error: Cannot redeclare register() (previously declared in 
/home/spikes/public_html/functions.php:2) in /home/spikes/public_html/functions.php 
on line 19

这是一段函数代码.php:

<?php
function register($username,$password,$email,$firstname,$lastname) /** LINE 2 **/
{
$con=connect();
if (mysqli_connect_errno())
  echo "Failed to connect to MySQL: " . mysqli_connect_error();

$date = date("Y/m/d");
$sql="INSERT INTO userlist (username, password, email, firstname, lastname, joined)
VALUES ('$username', '$password', '$email', '$firstname', '$lastname', '$date')";

if (!mysqli_query($con,$sql))
  die('Error2: ' . mysqli_error($con));

mysqli_close($con);
$id = getIdByUserName($username);
createSession($id,$firstname); /** LINE 19 **/
}

这是createSession:

function createSession($userid,$firstname)
{
$expire=time()+60*60*24*30;
setcookie("usid", $userid, $expire);
setcookie("usname", $firstname, $expire);
}

为什么它说我是redclaring register()??

1 个答案:

答案 0 :(得分:4)

我的猜测是你包括functions.php两次。试试require_once或小心。