Jump to content

Problem assigning value to variable in "IF" function


Recommended Posts

Does this script makes sense? I am trying to take the value that is set to "authenticat" and write it to authentication.

 

I think it is getting messes up by the $authenticat = "1" part.

 

Thanks

function check_username_pin($USERID, $PIN)
{
$query="SELECT id FROM users WHERE ( userid = '$USERID' AND pin = '$PIN' )";
// dont return pin because of hackers
$result=mysql_query($query);
if(mysql_num_rows($result)>0)
{
$authenticat = "1"
}
$query="SELECT id FROM users WHERE ( useris = '$USERID'  )";
// dont return pin because of hackers
$result=mysql_query($query);
if(mysql_num_rows($result)==0)
{
$authenticat = "2"; // bad id
}
$query="SELECT id FROM users WHERE ( pin = '$PIN' )";
// dont return pin because of hackers
$result=mysql_query($query);
if(mysql_num_rows($result)==0)
{
$authenticat = "3"; //bad pin
}
}

write("SET VARIABLE authentication $authenticat");

I am trying to use this script as a long in script that receives userid and pin from asterisk, and passess back whether or not the Userid/pin was good, and if not,why not

 

The write function writes it to a global variable for asterisk to use

You already have an existing thread for this problem. I suggest you continue in that thread instead of starting another one so you don't loose the history and information about what you are doing.

 

Why do you want to execute three queries now, when you can do all of that with a single query and a few lines of php code as mentioned in the other thread?

I am sorry about the two threads, I was switching around a lot.

The following is what was suggested to me in the other thread, the question is, how can I take the "return(1)" (for example) and assign it to a variable that is usable other places? Thanks

function check_username_pin($username, $pin)
{
$query="SELECT id FROM table WHERE ( username = '$username' AND pin = '$pin' )";
// dont return pin because of hackers
$result=mysql_query($query);
if(mysql_num_rows($result)>0)
{
return(1);
}
$query="SELECT id FROM table WHERE ( username = '$username'  )";
// dont return pin because of hackers
$result=mysql_query($query);
if(mysql_num_rows($result)==0)
{
return(2); // bad id
}
$query="SELECT id FROM table WHERE ( pin = '$pin' )";
// dont return pin because of hackers
$result=mysql_query($query);
if(mysql_num_rows($result)==0)
{
return(3); //bad pin
}
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.