dongwupei7803 2019-04-18 22:54
浏览 12

如何从其他文件访问我的变量?

I'm trying to access my variable $score from a different file but I keep getting an error message.

I've already tried adding global to it to make it a global variable and I've tried it without global.

My current code is below (not the whole files just a bit)

process.php file (lines 29 -34)

if($correct_choice == $selected_choice){
    global $score;
    $_SESSION['score']++;
    $score = $score++;
}

final.php file (lines 36 - 30)

You are Done!

Congrats! You have completed the test

Final score:

Take Test Again

I want the score users received in their quiz to display on the screen, however right now the error I keep getting is 'Notice: Undefined variable: score in C:\xampp\htdocs\project\phpstaff\quiz\final.php on line 30 T' Line 30 is <?php echo $score; ?>

In case you're wondering, I've already included <?php session_start(); ?> to both files and $_SESSION['score'] seems to be working fine.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏