PHP Fatal error: 'Can't use function return value in write context'

PHP Fatal error: 'Can't use function return value in write context'

嗨,我想知道是否有人可以帮助我。

我试过环顾四周,但我仍然不明白为什么我会得到这个 error.This 是每次加载页面时的错误:

PHP Fatal error: Can't use function return value in write context in G:\PleskVhosts\clubbit.co.uk\project\emailPassword.php on line 2

第 2 行是:

$_SESSION ('emailPassword') = $_POST ('forgotPasswordForm');

完整的 emailPassword.php 文档:

<?php @session_start(); //make the session remember the users names so they can be inserted on page
$_SESSION ('emailPassword') = $_POST ('forgotPasswordForm');
?>
<?php require_once('Connections/clubbit.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_emailPassword = "-1";
if (isset($_SESSION['emailPassword'])) {
  $colname_emailPassword = $_SESSION['emailPassword'];
}
mysql_select_db($database_clubbit, $clubbit);
$query_emailPassword = sprintf("SELECT * FROM users WHERE email = %s", GetSQLValueString($colname_emailPassword, "text"));
$emailPassword = mysql_query($query_emailPassword, $clubbit) or die(mysql_error());
$row_emailPassword = mysql_fetch_assoc($emailPassword);
$totalRows_emailPassword = mysql_num_rows($emailPassword);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
</body>
</html>
<?php
mysql_free_result($emailPassword);
?>

<?php

if ($totalRows_emailPassword > 0) { //only if an email exists

$from = "support.clubbit.co.uk"; //my email
$email = $_SESSION ('emailPassword'); //user email from form
$subject = "Clubbit Password Request"; //subject
$message = "Your Clubbit password is: ".$row_emailPassword['password']; //display password from recordset here

mail ($email, $subject, $message, "From: ".$from);

}

 if ($totalRows_emailPassword > 0) { //if success
  
  echo "Please check your email. Your password has been sent successfully!";
  
 }  else {                          //if fail
 
  echo "Fail - Please try again.";
 }
  
 

?>

忘记密码表格:

<form ACTION="emailPassword.php" method="POST" name="forgotPasswordForm" id="forgotPasswordForm">
 <div>
    <input name="email" type="email" required id="email" placeholder="Email" size="45">
    <input name="submit" type="submit" class="submit" id="submit" value="Email Password">
    </div>
  </form>

任何帮助都会很棒!

错误的括号:

$_SESSION['emailPassword'] = $_POST['forgotPasswordForm'];

标准圆括号()用于函数调用。错误的原因是 php 认为 $_SESSION(...) 是一个函数,因此您试图为函数调用赋值

你用错了括号

$_SESSION ('emailPassword') = $_POST ('forgotPasswordForm');

正确的代码是

$_SESSION['emailPassword'] = $_POST['forgotPasswordForm'];