JBTALKS.CC

标题: php 关于 session!! [打印本页]

作者: 狂天使    时间: 2010-3-7 10:33 PM
标题: php 关于 session!!
请问为何我run一下的code会出现这个error:Fatal error: Can't use function return value in write context??

我看了很久都不懂那里出问题!!

<?php

    // Initialize session data
    session_start();

    /*
     * If the user is already registered, display a
     * message letting them know.
     */
    if(isset($_SESSION['username'])) {
        echo "You're already registered as $_SESSION[username].";
    }

    // Checks if the form was submitted
    else if($_SERVER['REQUEST_METHOD'] == 'POST') {

        /*
         * If both the username and email fields were filled
         * out, save the username in a session variable and
         * output a thank you message to the browser. To
         * eliminate leading and trailing whitespace, we use the
         * trim() function.
         */
        if(!empty(trim($_POST['username']))
        && !empty(trim($_POST['email']))) {
                 
            // Store escaped $_POST values in variables
            $uname = htmlentities($_POST['username']);
            $email = htmlentities($_POST['email']);

            $_SESSION['username'] = $uname;

            echo "Thanks for registering! <br />",
                "Username: $uname <br />",
                "Email: $email <br />";
        }

        /*
         * If the user did not fill out both fields, display
         * a message letting them know that both fields are
         * required for registration.
         */
        else {
            echo "Please fill out both fields! <br />";
        }
    }

    // If the form was not submitted, displays the form HTML
    else {

?>

<form action="test.php?username=overwritten" method="post">
    <label for="username">Username:</label>
    <input type="text" name="username" />
    <label for="email">Email:</label>
    <input type="text" name="email" />
    <input type="submit" value="Register!" />
</form>

<?php } // End else statement ?>
作者: Super-Tomato    时间: 2010-3-8 04:42 AM
原帖由 狂天使 于 2010-3-7 10:33 PM 发表
请问为何我run一下的code会出现这个error:Fatal error: Can't use function return value in write context??

我看了很久都不懂那里出问题!!



如果這是你完整的 php 內容, 那麼就請注意粗體註明部分

        if(!empty(trim($_POST['username']))
        && !empty(trim($_POST['email']))) {

作者: 狂天使    时间: 2010-3-8 09:52 AM
我已经改了,忘记了empty不能放变量的

$username=trim($_POST['username']);
$email=trim($_POST['email']);
               
if(!empty($username) && !empty($email))

当我改成这样是没有error出现了,但是为什么我register不到呢?
作者: Super-Tomato    时间: 2010-3-8 11:03 AM
原帖由 狂天使 于 2010-3-8 09:52 AM 发表
我已经改了,忘记了empty不能放变量的

$username=trim($_POST['username']);
$email=trim($_POST['email']);
               
if(!empty($username) && !empty($email))

当我改成这样是没有error出现了,但是为什 ...



這就不清楚了, 基本上除了第一帖看到的 empty 參數使用錯誤外應該就沒什麼錯誤了, 如果還有應該就是你本身 server 的設置問題或其他 coding 影響


p/s: empty 參數必須是變量

[ 本帖最后由 Super-Tomato 于 2010-3-8 11:05 AM 编辑 ]
作者: 狂天使    时间: 2010-3-8 11:18 AM
我找到问题了是我的action="test.php" 我已经换了file name但是忘记将里面action="test.php" 换了 无言.... 但是还是要谢谢你哦!




欢迎光临 JBTALKS.CC (https://jbtalks.my/) Powered by Discuz! X2.5