dimanche 12 avril 2015

How do I pass then use multiple variables in a php function?


Vote count:

0




In my form I have the following code:



$id = 123;
$username = (validate_username($_POST['username']));


In a function I have:



function val_username ($data)
{
$data = trim($data);
if(isset($_POST['username']) && !empty($_POST['username']))
{
$username=strtolower(($_POST['username']));
$query="select * from sp_users where LOWER(username)='$username'";
if ( $id ) { $query="select * from sp_users where LOWER(username)='$username' and id != $id"; }
$res=mysql_query($query);
$count=mysql_num_rows($res);
if($count > 0){ $fail = true; $msg .= "The username is already in use."; }
}
return ($data);
}


There is a little more to the function than the above but that is the gist of it. What I don't understand is how to pass a second variable to the function, $id and use it in the function? Rather than:



$username = (validate_username($_POST['username']));


Something like:



$username = (validate_username($_POST['username']),$id);


Then use it in the function and returning only the checked username. I can handle success/failure.



asked 41 secs ago







How do I pass then use multiple variables in a php function?

Aucun commentaire:

Enregistrer un commentaire