Solved

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

Posted on 2007-12-04
12
236 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:Alan-Yeo
  • 4
  • 4
  • 4
12 Comments
 
LVL 27

Accepted Solution

by:
yodercm earned 400 total points
Comment Utility
if ($status == 0)
  return TRUE;
else
  return FALSE:
0
 
LVL 27

Assisted Solution

by:yodercm
yodercm earned 400 total points
Comment Utility
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:yodercm
Comment Utility
Sorry, missed a " mark :))

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

Expert Comment

by:steelseth12
Comment Utility
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:Alan-Yeo
Comment Utility
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 100 total points
Comment Utility
if($activatedresult =  true){

should be

if($activatedresult == true){

= is an assignment operator .. you have to use == for comparisons
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Alan-Yeo
Comment Utility
ok, stil not working... "boo hoo" is displayed even though the sql database has been updated.
0
 
LVL 20

Expert Comment

by:steelseth12
Comment Utility
put quotes around $pass in your query

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

Author Comment

by:Alan-Yeo
Comment Utility
the query doesn't work with quotes around $pass
0
 
LVL 20

Expert Comment

by:steelseth12
Comment Utility
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:Alan-Yeo
Comment Utility
used parts of all your solutions. Thanks for the help
0
 
LVL 27

Expert Comment

by:yodercm
Comment Utility
$q = "UPDATE TBL_USERS SET status = '1' WHERE (password = '$pass') AND (username = '$user')";
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now