Note that there are some explanatory texts on larger screens.

plurals
  1. POSearch for a term in mssql via php depending on an inconstant variable
    primarykey
    data
    text
    <p>Basically, I have a login panel where users can login and what I am trying to do is when they login I want to find out their Authentication ID that has been set in the MSSQL database.</p> <p>The database looks like this:</p> <p><a href="http://i.stack.imgur.com/92qEN.png" rel="nofollow">http://i.stack.imgur.com/92qEN.png</a></p> <p>And I want to be able to get the 'AuthID' of the user and make it 'die' (die $result) so that the result is shown in the browser.</p> <p>At the moment I have this code and with it I am able to get the AuthID but it doesn't get the specific user that is logging in. It gets every single AuthID in the database.</p> <pre><code>&lt;?php $myServer = "Farbod-PC\SQLExpress"; $myUser = "user"; $myPass = "pass"; $myDB = "Account"; $dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer"); $selected = mssql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB"); $query = "SELECT nAuthID FROM tAccounts"; $result = mssql_query($query) or die('A error occured: ' . mysql_error()); while ( $record = mssql_fetch_array($result) ) { die ($record ['nAuthID']); } mssql_free_result($result); mssql_close($dbhandle); ?&gt; </code></pre> <p>To give an example, say I login with the user 'MrFarbodD' I want it to be able to output the AuthID of MrFarbodD which is 2, in the browser.</p> <p>EDIT:</p> <p>I'm going to provide more information about the problem so it's better understood.</p> <p>I have a program that allows you to login when you type your password and username in correctly. This works by my program sending information to the web server which then replies in the browser if it's correct or not. Then my program downloads that string and if it is a certain text then it's correct and it logs you in and starts the main program.</p> <p>Now what I want to do is be able to do this but then I also want to be able to get the nAuthID so I can make it so that only people with an nAuthID of 2 can login. I want to do this by first when the user enters their password and username their AuthID is found and then sent in the browser which can then be downloaded as a string by the program.</p> <p>This is the code that checks their passwords and sets their token to log in.</p> <pre><code> &lt;?php error_reporting(E_ERROR); $conf['db_host'] = "Farbod-PC\SQLExpress"; $conf['db_user'] = "user"; $conf['db_pass'] = "pass"; $conf['db_name'] = "Account"; $user = sql_clean($_GET['Username']); $passhash = sql_clean($_GET['Password']); $con = mssql_connect($conf['db_host'],$conf['db_user'],$conf['db_pass']) or die('Database connect Fail.'); $db = mssql_select_db($conf['db_name'], $con) or die('Database Init Fail.'); $exec = mssql_query("SELECT nEMID, sUserPass FROM tAccounts where sUsername = '$user'"); if($exec) { if(mssql_num_rows($exec) != 1) { die('wud'); } $AccountData = mssql_fetch_assoc($exec); $PlaintxtPass = $AccountData['sUserPass']; $PlaintxtnEMID = $AccountData['nEMID']; if (MD5($PlaintxtPass) == $passhash) { $Token = RandomToken(35); $setToken = null; if (mssql_num_rows(mssql_query("SELECT * FROM tTokens WHERE nEMID = '".$PlaintxtnEMID."'")) &gt;= 1) { mssql_query("DELETE FROM tTokens WHERE nEMID = '".$PlaintxtnEMID."'"); $setToken = mssql_query("INSERT INTO tTokens (nEMID, sToken) VALUES('".$PlaintxtnEMID."', '".$Token."')"); } else $setToken = mssql_query("INSERT INTO tTokens (nEMID, sToken) VALUES('".$PlaintxtnEMID."', '".$Token."')"); if ($setToken) die('OK#'.$Token); else die('SetToken Error'); } else { die('wud'); } } else { die('Query Failed'); } mssql_close(); function sql_clean($str) { $search = array("\\", "\0", "\n", "\r", "\x1a", "'", '"'); $replace = array("", "", "", "", "", "", ""); return str_replace($search, $replace, $str); } function RandomToken( $length ) { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $str = ""; $size = strlen( $chars ); for( $i = 0; $i &lt; $length; $i++ ) { $str .= $chars[ rand( 0, $size - 1 ) ]; } return $str; } ?&gt; </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload