我收到以下错误:
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()??
答案 0 :(得分:4)
我的猜测是你包括functions.php
两次。试试require_once
或小心。