Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-12-04
12
Medium Priority
?
254 Views
Last Modified: 2010-04-21
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
Comment
Question by:Antonio King
  • 4
  • 4
  • 4
12 Comments
 
LVL 27

Accepted Solution

by:
Cornelia Yoder earned 1600 total points
ID: 20402210
if ($status == 0)
  return TRUE;
else
  return FALSE:
0
 
LVL 27

Assisted Solution

by:Cornelia Yoder
Cornelia Yoder earned 1600 total points
ID: 20402214
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
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 20402215
Sorry, missed a " mark :))

if ($status == 0)
  return "account not activated";
else
  return "account activated";
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 20

Expert Comment

by:steelseth12
ID: 20402221
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
 

Author Comment

by:Antonio King
ID: 20402674
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
 
LVL 20

Assisted Solution

by:steelseth12
steelseth12 earned 400 total points
ID: 20402696
if($activatedresult =  true){

should be

if($activatedresult == true){

= is an assignment operator .. you have to use == for comparisons
0
 

Author Comment

by:Antonio King
ID: 20402728
ok, stil not working... "boo hoo" is displayed even though the sql database has been updated.
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 20402756
put quotes around $pass in your query

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

Author Comment

by:Antonio King
ID: 20402796
the query doesn't work with quotes around $pass
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 20402827
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
 

Author Closing Comment

by:Antonio King
ID: 31412556
used parts of all your solutions. Thanks for the help
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 20403034
$q = "UPDATE TBL_USERS SET status = '1' WHERE (password = '$pass') AND (username = '$user')";
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question