• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Hopw do i return a true or false result from a function

I have created this function...
function ActivateAccount(){
      global $database;
      $pass = stripslashes($_GET['hash']);
      $user = base64_decode($_GET['stamp']);
      $q = "UPDATE ".TBL_USERS." SET status = '1' WHERE (password = $pass) AND (username = '$user')";
      $database->query($q);
}

Would like to know, how to pass some kind of string or something that i can use later on in the document...

like...

<? if($status == 0){
?>
account not activated
<? }else{ ?>
account activate!
<? } ?>

How do I do this?
0
Antonio King
Asked:
Antonio King
  • 4
  • 4
  • 4
3 Solutions
 
Cornelia YoderArtistCommented:
if ($status == 0)
  return TRUE;
else
  return FALSE:
0
 
Cornelia YoderArtistCommented:
Or you could return the string itself with

if ($status == 0)
  return "account not activated";
else
  return "account activated;

and then where you call the function, just use

$activatedresult = ActivateAccount;

and the variable $activatedresult will contain whichever of those strings applies.
0
 
Cornelia YoderArtistCommented:
Sorry, missed a " mark :))

if ($status == 0)
  return "account not activated";
else
  return "account activated";
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
steelseth12Commented:
function ActivateAccount(){
      global $database;
      $pass = stripslashes($_GET['hash']);
      $user = base64_decode($_GET['stamp']);
      $q = "UPDATE ".TBL_USERS." SET status = '1' WHERE (password = $pass) AND (username = '$user')";
      $database->query($q);
        
        if($database->affected_rows){
        
              return "account activate!";
        
        }else{
        
              return "account not activated";
        
        }
        
        
}
0
 
Antonio KingIT ManagerAuthor Commented:
ok ... still not working as i'd like.

<? include("include/session.php");
function ActivateAccount(){
      global $database;
      $pass = stripslashes($_GET['hash']);
      $user = base64_decode($_GET['stamp']);
      $q = "UPDATE ".TBL_USERS." SET status = '1' WHERE (password = $pass) AND (username = '$user')";
      $database->query($q);
    if($database->affected_rows){
            return true;
      }else{
            return false;
      }
}
?>

<?
$activatedresult = ActivateAccount();
if($activatedresult = true){
      echo "congratulations";
}else{
      echo "boo hoo ";
}

IT always returns congratulations... even when the sql database is not updated.
0
 
steelseth12Commented:
if($activatedresult =  true){

should be

if($activatedresult == true){

= is an assignment operator .. you have to use == for comparisons
0
 
Antonio KingIT ManagerAuthor Commented:
ok, stil not working... "boo hoo" is displayed even though the sql database has been updated.
0
 
steelseth12Commented:
put quotes around $pass in your query

 $q = "UPDATE ".TBL_USERS." SET status = '1' WHERE (password = '$pass') AND (username = '$user')";
0
 
Antonio KingIT ManagerAuthor Commented:
the query doesn't work with quotes around $pass
0
 
steelseth12Commented:
you get an error ?

try the following lines

$q = "UPDATE ".TBL_USERS." SET status = '1' WHERE (`password` = '$pass') AND (username = '$user')";

$database->query($q) or die($database->error);
0
 
Antonio KingIT ManagerAuthor Commented:
used parts of all your solutions. Thanks for the help
0
 
Cornelia YoderArtistCommented:
$q = "UPDATE TBL_USERS SET status = '1' WHERE (password = '$pass') AND (username = '$user')";
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now