Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Error message Can't use function return value in write context

New Here ,
Nov 16, 2008 Nov 16, 2008

Copy link to clipboard

Copied

I keep getting the "Can't use function return value in write context" error when I try to pull a dataset from a MySQL database using a form-variable from a previous page. I've spent days digging through webposts and a Php and MySql reference book trying to understand what's going wrong and I'm getting nowhere.

The error message references line 33. What I want to happen is on a previous page a person selected themselves from a dynamic list and it set the value of varDirector to their ID in a table of Directors. That number is passed as a form variable to the page where the error occurs (see code below). The SQL query runs when I test but then when I upload the pages and try to run I get the error. Is it something to do with whether the variable is a number or text string?

Thanks for any help.

TOPICS
Server side applications

Views

415
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 17, 2008 Nov 17, 2008

Copy link to clipboard

Copied

trsanfor wrote:
> The error message references line 33. What I want to happen is on a previous
> page a person selected themselves from a dynamic list and it set the value of
> varDirector to their ID in a table of Directors. That number is passed as a
> form variable to the page where the error occurs (see code below).

The code that you have posted does not contain anything that would
generate the error message you refer to. Since you're passing
information from one page to the next, it's more likely that the error
is generated on the previous page.

"Can't use function return value in write context" means that you have
nested a function in an illegal place. It often occurs with empty(). For
example,

// CAUSES AN ERROR
if (!empty(trim($_GET['myVar']))

// SAFE
$myVar = trim($_GET['myVar']);
if (!empty($myVar))

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 17, 2008 Nov 17, 2008

Copy link to clipboard

Copied

Thanks for your response, but I'm afraid I'm still at a loss. I'm attaching the code from the previous page to see if you can help me find where the error is occurring.

Thanks!

<?php require_once('../Connections/Registration.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}

mysql_select_db($database_Registration, $Registration);
$query_rsDirectors = "SELECT CONCAT(Directory.Firstname,' ',Directory.Lastname) AS Director, Directory.ID, Directory.MENC_ID FROM Directory ORDER BY Directory.Lastname, Directory.Firstname";
$rsDirectors = mysql_query($query_rsDirectors, $Registration) or die(mysql_error());
$row_rsDirectors = mysql_fetch_assoc($rsDirectors);
$totalRows_rsDirectors = mysql_num_rows($rsDirectors);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Prepare Registration Verification</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="Print_Registration.php">
<p> <label for="varDirector">Select your name:</label>
<select name="varDirector" size="1" id="varDirector">
<?php
do {
?>
<option value="<?php echo $row_rsDirectors['ID']?>"><?php echo $row_rsDirectors['Director']?></option>
<?php
} while ($row_rsDirectors = mysql_fetch_assoc($rsDirectors));
$rows = mysql_num_rows($rsDirectors);
if($rows > 0) {
mysql_data_seek($rsDirectors, 0);
$row_rsDirectors = mysql_fetch_assoc($rsDirectors);
}
?>
</select>
</p>
<p>
<input type="submit" name="button" id="button" />
</p>
</form>
</body>
</html>
<?php
mysql_free_result($rsDirectors);
?>

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 17, 2008 Nov 17, 2008

Copy link to clipboard

Copied

LATEST
trsanfor wrote:
> Thanks for your response, but I'm afraid I'm still at a loss. I'm attaching the
> code from the previous page to see if you can help me find where the error is
> occurring.

Nothing obvious there. What does the full error message say? It refers
to line 33, but what's on line 33 of the file mentioned in the error
message?

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines