//for login
function login(){
$user=$_POST['user'];
$pass=$_POST['pass'];
$sql="select * from account where username='".$user."' AND password='".$pass."'";
$sql2=mysql_query($sql);
}
//pass the $sql2 to the check function
function check(){
login($sql2);
while($row=mysql_fetch_array($sql2)){
echo $a=$row['username'];
echo $b=$row['id'];
echo $c=$row['password'];
}
}
check();
<?php //for login function login() { $user = $_POST['user']; $pass = $_POST['pass']; $sql = "select * from account where username='" . $user . "' AND password='" . $pass . "'"; $sql2 = mysql_query($sql); return $sql2; // <<------------<<<<<<<<<
} //pass the $sql2 to the check function function check() { $sql2 = login(); // <<----------<<<<<<<<<< while ($row = mysql_fetch_array($sql2)) { echo $a = $row['username']; echo $b = $row['id']; echo $c = $row['password']; } } check();
PS: you should probably add some defensive coding in the second function to make sure the returned value is not false. I would avoid using "global" in pretty much any case I can imagine, but putting this into a class and going object-oriented is a good idea (if you have the time to learn it right and not just throw a bunch of procedural functions into a class container).
Last edited by NogDog; 04-27-2012 at 08:52 AM.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
sorry but i'm just a newbie in using function.. anyway after researching i did figured out on how to fix the problem.. i just use this reference function to get my desired output... but the problem is...
PHP Code:
//for login
function login(&$user,&$pass){ $user; $pass; } login($a=$_POST['user'],$b=$_POST['pass']); echo $a,"<br>"; echo $b,"<br>";
i get this error
PHP Code:
Strict Standards: Only variables should be passed by reference in
the good thing is the variables at $a, and $b successfully displayed the output, but i get the error from the above.
I see no reason to pass anything by reference at this point.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks