Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-12-04
12
Medium Priority
?
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

719 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