ghurty Posted October 26, 2009 Share Posted October 26, 2009 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"); Quote Link to comment https://forums.phpfreaks.com/topic/179020-problem-assigning-value-to-variable-in-if-function/ Share on other sites More sharing options...
trq Posted October 26, 2009 Share Posted October 26, 2009 Does this script makes sense? Its incredibly inefficient, but yeah.... What does the write() function do exactly? Quote Link to comment https://forums.phpfreaks.com/topic/179020-problem-assigning-value-to-variable-in-if-function/#findComment-944514 Share on other sites More sharing options...
ghurty Posted October 26, 2009 Author Share Posted October 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/179020-problem-assigning-value-to-variable-in-if-function/#findComment-944517 Share on other sites More sharing options...
PFMaBiSmAd Posted October 26, 2009 Share Posted October 26, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/179020-problem-assigning-value-to-variable-in-if-function/#findComment-944520 Share on other sites More sharing options...
ghurty Posted October 26, 2009 Author Share Posted October 26, 2009 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 } } Quote Link to comment https://forums.phpfreaks.com/topic/179020-problem-assigning-value-to-variable-in-if-function/#findComment-944532 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.