Jump to content

Can't use function return value in write context


BrandonLayton
 Share

Recommended Posts

This is my error:

Fatal error: Can't use function return value in write context in /home/a8152576/public_html/SecretSanta.html on line 41

 

confused about why.

This is the line 41:

if(isset($_POST('submit')){

 

this is the php of my page (without the mysql data):

<?php
class functions{
public static function chooseGiftee($SS){
    	$done = false;
        while($done=false){
    		$sqllink= mysql_connect($mysql_host,$mysql_user,$mysql_password);
    		if(!$sqllink){
    			echo "Could not connect! Please Try Again";
    		    mysql_close($sqllink);
    		} else {
    			$selectGiftee = "SELECT * FROM SecretSantas ORDER BY RAND() LIMIT 0,10;";
        	    while($row=mysql_fetch_array($result)){
                	$results = mysql_query($selectGiftee);
        	    	if(!$row['Gifter']=''){
        	        	$done=false;
        	        } else {
        	    		$gifteeResults = $row['Name'];
                        $addSS = "INSERT INTO SecretSantas (Gifter) VALUES ('" .$SS. "')";
                        $done=true;
        	    		return $gifteeResults;
        	        }
        	    }
    		}
            mysql_close($sqllink);
        }
    }
}

if(isset($_POST('submit')){
$echoName = functions::chooseGiftee($_POST['gifterName']);
echo $echoName;
}
?>

 

This is html:

<form id="form1" name="form1" method="post" action="">
  <p>
    <label>Your Name:
      <input type="text" name="gifterName" id="gifterName" />
    </label>
    <input type="submit" name="submit" id="submit" value="Submit" />
  </p>
  <p> </p>
</form>

 

Confused about the issue, first time using functions.

Thanks in advance,

Brandon

Link to comment
Share on other sites

Sorry, I obviously completely misread your code (at work, with a few people around).

 

Anyway, there really is no need for a class here at all. Classes shouldn't be used to simply group functions together, theres allot miore to them than that. I understand hwoeever that your likely just trying to learn the syntax.

 

Theres quite a few errors with your code. Classes, like functions have there own scope. That means, all those arguments passed to mysql_connect() do not exist. Not likey the cause of your issue, but it's where I'm starting.

Link to comment
Share on other sites

Having a better look at your code now. I would forget all about classes and functions for a while, you might need to revise some php basics.

 

Your code really makes little sense.

 

The entire process run in a while() loop, why?

 

Your try and execute another while loop passing $result to mysql_fetch_array() yet $result is not defined.

 

Within that loop you execute a query and then do nothing with $results.

 

Really, it is all over the place.

Link to comment
Share on other sites

Ok thanks for the reply.

 

Oops. Shouldn't have $results in the loop... and that loop should be an if statement if I am correct this time :P

 

The purpose of the while loop is to make sure that the row does not already have a value for 'Gifter'. Not sure how else I can do that.

 

As you can probably tell I am pretty new to php...

Link to comment
Share on other sites

This is my attempt:

<?php
public static function chooseGiftee($SS){
   	$done = false;
    $sqllink= mysql_connect($mysql_host,$mysql_user,$mysql_password);
   	if(!$sqllink){
   		echo "Could not connect! Please Try Again";
   	 	mysql_close($sqllink);
   	} else {
   		$selectGiftee = "SELECT * FROM SecretSantas ORDER BY RAND() WHERE 'Gifter' = '' LIMIT 0,10";
        $results = mysql_query($selectGiftee);
       	$row=mysql_fetch_array($result)
       	    if(!$row['Gifter']=''){
       	        $done=false;
       	    } else {
       	    	$gifteeResults = $row['Name'];
                $addSS = "INSERT INTO SecretSantas (Gifter) VALUES ('" .$SS. "')";
                $done=true;
       	    	return $gifteeResults;
       	    }
   	}
    mysql_close($sqllink);
}
?>

 

Error:

Parse error: syntax error, unexpected T_PUBLIC in /home/a8152576/public_html/SecretSanta.html on line 14

That is on this line:

public static function chooseGiftee($SS){

Little confused about why its saying it shouldn't be public.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.