在服务器中运行时出现PHP错误

时间:2014-04-23 09:23:22

标签: php mysql

我遇到以下错误并检查了代码(我不是专家,而是初学者)

有人请帮助。

Err Msg:

( ! ) Fatal error: Call to undefined function session_register() in C:\wamp\www\11\session.php on line 3


Call Stack


>#

>Time

>Memory

>Function

>Location

>1 0.0030 179560 {main}( ) ..\index.php:0 
>2 0.0060 237472 include_once( 'C:\wamp\www\11\template.php' ) ..\index.php:342 
>3 0.0740 254304 include_once( 'C:\wamp\www\11\session.php' ) ..\template.php:3 

Index-PHP(开始)

<?php 
function main()
{
$config=mysql_fetch_array(mysql_query("select * from sbjbs_config"));
$policies=mysql_fetch_array(mysql_query("select * from sbjbs_policies"));
$cid=0;

    $suspended_list="-1";
    $mem_q=mysql_query("select * from sbjbs_employers where sb_suspended='yes'");
    while($mem=mysql_fetch_array($mem_q))
    { $suspended_list.=",".$mem["sb_id"];}

    $disapproved_list="-1";
    $comp_q=mysql_query("select * from sbjbs_companies where 
    (sb_approved='no' OR sb_uid in ($suspended_list))");
    while($comp=mysql_fetch_array($comp_q))
    { $disapproved_list.=",".$comp["sb_id"];}

?>
<table width="100%" border="0" cellspacing="10" cellpadding="2" class="maintablestyle">
  <tr> 
    <td valign="top"><table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="onepxtable">
        <tr> 
          <form name="form1" method="post" action="search_result.php">
            <td align="center" valign="middle" class="innertablestyle"><br> <input name="keyword" type="text" size="40"> 
              &nbsp;&nbsp; <select name="loc_id">
                <option value="" selected>Any Location</option>
                <?php
                $loc_query=mysql_query("select * from sbjbs_locations where sb_pid=0 order by sb_default desc,sb_loc_name");
                while($loc=mysql_fetch_array($loc_query))
                {
                ?>
                <option value="<?php echo $loc["sb_id"];?>"><?php echo $loc["sb_loc_name"];
                ?></option>
                <?php 
                }
                ?>

Index-PHP文件中的第343行

    <?php
}
include_once ('template.php');
?>

Sessions-php文件

    <?php
session_start();
session_register("sbjbs_username");
session_register("sbjbs_userid");
session_register("sbjbs_memtype");
session_register("sbjbs_emp_username");
session_register("sbjbs_emp_userid");
//session_register("ID");
?>

有人请帮我解决这个问题......;提前致谢

3 个答案:

答案 0 :(得分:3)

session_register()已被弃用,请参阅manual了解更多信息

使用$_SESSION['var'] = "value"

的变量

有关详情: - How to fix the session_register() deprecated issue?

和服务器上的错误导致不同的PHP版本

session_start();
$_SESSION["sbjbs_username"] = 'value';
$_SESSION["sbjbs_userid"] = 'value'; 

等等

答案 1 :(得分:1)

session_register("sbjbs_username");

这不是最正确的方法..函数session_register()很久以前就被弃用了......你应该这样做:

$_SESSION['sbjbs_username'] = 'something';

答案 2 :(得分:0)

session_register()已被弃用,您不再需要注册变量 您可以轻松地将$_SESSION['variablename']用于会话变量。

示例:

$_SESSION["ID"]=$id;
$_SESSION["name"]=$name;

参见指南here