berserk 60 Junior Poster

no the string values in my code are case sensitive, i just forgot to make the example tables above case sensitive.

the example should have a Checked value and not checked

berserk 60 Junior Poster

So here is my problem laid out as simple as I can put it.
I cant combine multiple entities together that have related data but are different
(one database table has id number that is shared by database table 2 and table 2 has employee number which is shared with database table 3, I need to limit the active employees in table 3 while searching for the current employees with id number “Something” because table 1 has their job details, which are also marked as active or none active and need to be limited in that search as well)

Table 1

Id_num          Job_desc            Job_active
123123          supervisor         checked
123123          advisor           unchecked

Table 2

Id_num       Job_id       Employee_number
123123       B04           29928
234234       B00           29999

Table 3

Employee_number        Employee_active        Employee_name
29928                               true             Alfred
29999                               false            Batman

My dilemma is that I need to combine all these table into one searchable query either using LINQ entities or just plain sql (I do not care which at this point) and then return the results as a list and print them on a view inside my app.

This is what I have so far and I know its very wrong because I have no idea what to do or what direction is better, I read that raw sql is better but then I read that its better to do what I have done below. Any guidance is appreciated, and please using coding examples in responses so I can better understand any points you might …

berserk 60 Junior Poster

I haver an IIS server with an mvc 5 app im developing and i have had no luck so far getting the windows authentication working with my app, i have it set to windows authenication but the app will only auto login users when accessed from the server. Then once you click logout it will prompt you for a username and password which is right and log you in accordingly, good so far, but then when you go to log out of that user you are not prompted but just reset back to the default local user of the computer which is NOT what i need.

I want the user to have to login to access the app, then when they click logout they are met with a log in screen, an di want the username and password to be the useranem and password one would you to access the current network they are on. So far i have only part of this but it isnt right. I believe the error code the login is returning is the whole reason im even able to switch users to begin with because it takes you to the error page no matter if you are a user or not, this is definitly wrong.

Is there additional code i need to put in for my account controller to be able to prompt for a windows login correctly without this mess i have.

If any code is needed ill glad post, just really looking for …

berserk 60 Junior Poster

OK! So i have had what some might consider to be a rough week and this is where i am with this monstrosity thats been literally dumped in my lap.

I have modified the code using the fix above and still i am getting the duplicates but before you RAGE!!!!! let me give more context...

The reason i have the subtract tables is because the genious who designed the sql database seperated all the departments into their own table and then some how managed to generate some random ass number that didnt get duplicated once, then when i come around and rewrite it using what i thought was the same logic (going from visual basic to php) i end up getting these stupid duplicates...

i stripped the original code down cause i thougth maybe it was just the whole single department thing but turns out its generating dups in the co op departments so here is the code that i have so far that i believed to be working until i found out that its still letting dups through

if ($co_partner === "yes") {
    do {
        $random_number = rand(10000,10000000);
        $sql = "(SELECT sec_id FROM depart_table0 WHERE sec_id='".$random_number."')";
        for ($i=0; $i < $table_count[0]-7; $i++){
            $sql .= "UNION (SELECT sec_id FROM depart_table".$i." WHERE sec_id='".$random_number."')";
        }
        $sql_response = mysqli_query($con, $sql)or die(mysqli_error($con));

        $sql2 = "(SELECT sec_id_cop FROM depart_table0 WHERE sec_id_cop='".$random_number."')";
        for ($i=0; $i < $table_count[0]-7; $i++){
            $sql2 .= "UNION (SELECT sec_id_cop FROM depart_table".$i." WHERE sec_id_cop='".$random_number."')";
        }
        $sql_response2 = mysqli_query($con, $sql2)or die(mysqli_error($con));

    } while (mysqli_num_rows($sql_response) …
berserk 60 Junior Poster

lol oh believe me i whole heartedly agree, i would have done things very different if i had started a project like this from the beginning but the biggest roadblock im running into is basically the people im attempting to rewrite this for already have a sql database in place with the above mentioned structure of have all the departments seperated into their own unique table which has been a royal pain to code around. I have mentioned compiling all the data into one table and working from there but the feel i should write my code around what they already have... its kinda one of those scenarios where some older guys are telling me "its good enough, dont go changing anything that doesnt need to be changed" so i get mixed results on updates with them but basically they want me to write a script to modify the duplicates and make them unique, then apply this fix i have worked out with you travel.

I thank you so very much for your time and you insight into better practices, I feel better prepared for when i tackle a project where i decide what goes instead of the people im doing it for.

HAPPY CODING! :D

berserk 60 Junior Poster

thank you so much for all your time! :D this has been extremely informative and i must say i have learned quite a bit and now feel a little more confident in how to think through this. I have talked to the higher ups and they explained to me that they want it as similar as it can be, so changing the size of the numbers is no good, but what i feel i can do is change the logic behind my orginal code to accomidate the multiples, please tell me if im on the right track with this.

do {
        $random_number = rand(10000,10000000);
        $sql = "(SELECT sec_id FROM depart_table0 WHERE sec_id='".$random_number."')";
        for ($i=0; $i < $table_count[0]-7; $i++){
            $sql .= "UNION (SELECT sec_id FROM depart_table".$i." WHERE sec_id='".$random_number."')";
        }
        $sql_response = mysqli_query($con, $sql)or die(mysqli_error($con));
    } while (mysqli_num_rows($sql_response) >= 1);

i know its a small change but would the greater than or equal to 1 solve my problem? I have read over and i believe my dups are coming not from this but from the fact that i have potentially more than one match whereas i was only checking for a single match there might be 2 or even 3 and that would cause it to resolve early.

I love how you stepped through my logic above because i feel that was what helped open my eyes a little better to what i initally wanted in the beginning. :)

berserk 60 Junior Poster

i wanted to go with the unique id idea before but im not sure how to add that and still have it work across all tables. Can you have two unique id columns in one table? Also i really like the idea of find the largest value and then just incrementing from there, im not sure why it wasnt setup like that to begin with but again this is just a rewrite of what they had before.

as fo the number of digits i guess it just has to be within that random number range, they havent given me to much info on that so im doing a lot of assuming lol.

The UUID_SHORT() how exactly does that work? Does is garuntee that the chances of making an id that are the same is near impossible or does it look into what i have and generate one based on non existing values?

berserk 60 Junior Poster

thank for the speedy reply! :D

and yeah as for the code generating sec_id's, that code is in the do while loop i posted, and yes the test sec_id's are fake i just through some random numbers in there to show an example sorry bout that lol

My next question though is, isnt the random number being recreated when the do runs again if the while comes back true?

my thoughts on this were that the random number is being generated and then tested against the system to check if its already in there, then if it is just run it again and generate another random number and check again. Is this incorrect?

berserk 60 Junior Poster

SO Basically i have this problem with this test build of a little project im rewriting and so far its not looking to good

I have multiple tables that are all the same, they have been set up this way for simplicity as far as i can tell.

Tables

+----+----------+-----------------+---------------+-------------------+
| id | sec_id   | customer_name   | customer_date | etc...            |
+----+----------+-----------------+---------------+-------------------+
| 0  | 14328778 | Somebody Once   | 2/1/2016      | Role Me I         |
+----+----------+-----------------+---------------+-------------------+
| 1  | 14428755 | Told Me The     | 2/6/2015      | Aint The Sharpest |
+----+----------+-----------------+---------------+-------------------+
| 2  | 15548447 | World Was Gonna | 2/12/2014     | Tool in the shed  |
+----+----------+-----------------+---------------+-------------------+

As you can see from my table above i have the regular id and then this second id
the problem is in the second id number because thats where my duplicates are.

I have about 25 tables like the one above and they are all the same but for different departments and have all different data but are all basically used in the same way

I am in the process of attempting reporting/inserting data into these tables without creating any duplicates and so far i have failed miserably at this
because i have some reported 55 duplicates over the past week out of nearly 1000 entries and while this might not seem like a big deal its continueing to be a huge headache for me because i cant get the data from the tables if one of the …

berserk 60 Junior Poster

NEVERMIND, lol if i had done more testing and reading then i might have figured out how to work angular before asking so quickly. I learned about manipulating the data before it hits the page rather than changing it on the page itself. Sorry to bother everyone.

berserk 60 Junior Poster

Hello All, i have run into an issue with my little project that i cannot seem to find much on and im at a lose for resources to check through.

I am trying to get and use data that is being pulled from a json echo to my other php page but it is being echoed in real time due to ajax and a new javascript im not fimiliar with called angular that i am currently trying to learn which is probably why im stuck in the first place.

here is my echo line in my ph file

$result = $mysqli->query($sql);
    $data = $result->fetch_assoc();

    echo json_encode($data);

that comes from my php file through the jquery call from my javascript file

$scope.edit = function(temp_id){
    dataFactory.httpRequest(URL + '/api/details.php?member_id='+member_id).then(function(data) {
        console.log(data);
        $scope.form = data;
    });
  }

now i know this works because in my html i can see the data come through in real time if i do something like this

echo "{{form.select_consumer_state}}";

or something in just plain html like so

<h4>Details for {{form.name_of_the_consumer}}</h4>

there is also this

<td>{{ value.date_range }}</td>

these ways of getting the data back on the page are very new to me, or maybe i jast havent been doing this long enough but this code uses some javascript called angular and when i go to use the variables in any of my php or javascript it simply doesnt work. I need to know how to can go about using this data in php or javascript, either …

berserk 60 Junior Poster

i think those first few items might be what im looking for, i never really thought to look back through the function i created but now i feel like i need to revisit it. Ill keep you posted on any updates, again thank you so much for your assistance! :D

berserk 60 Junior Poster

I have a very old and very slow server :/ i always thought that was normal since im running on such old hardware and slow disks

berserk 60 Junior Poster

they are, and please excuse my lack of detail but ill describe this the best i can.

when clicking the href link and going to another page, while the new page is loading before it begins loading the new page i have time to click another link which will cause it to pause for a second and then it will kick me out, or at least i know my sessions are being destroyed which is causing the kick

berserk 60 Junior Poster

the hrefs are relative paths

I try my best to be neutral about those subjects because no matter which side you pick you will always end up pissing someone off in the end. I prefer linux though but mainly because its free and the community (like daniwebs) is great ^ u ^

berserk 60 Junior Poster

i will try to give an answer to every variable, im a bit tired lol so try to bare with me if something sounds weird

The pages are all built server side
i am doing href redirects through an html navigation bar i built
its not on a refresh that doesnt seem to hurt anything for some reason
it si all the pages, no matter where im coming from
and yes i use a sec_session_start function at the top of every page literally EVERY page

and the reason i said that about the platform is because i went to a convention not to long ago and got some serious dirty looks and commetns for using what is essentially open source on a microsoft platform.

finally, thank you for the quick response! :D

berserk 60 Junior Poster

platform: IIS + Apache + mysql + php (please dont justdge me on the platform it was not my choice)

I have this weird bug that seems to be directly related to my sessions on my web based app.

when i travel between links, if i give the previous page enough time to fully load i am fine, but when traveling from page to page if i click another page link before the previous one has finished loading then i suddenly get kicked back tot eh login screen. I dont understand why this is happening and i cant seem to find much about it online anywhere either.

Oh please great wisdom of the daniweb members, here my call, answer this ulcer inducing question i have been stuck on for days.

Thank you for all of your assistence!

berserk 60 Junior Poster

I have modified permissions, edited config files, and rewritten my code several times and no results whatsoever. I am at a dead end and I have no way around this that I have come up with or been able to find online though countless help forums. The error that I am having seems so simple but has become a major roadblock.
I have a php script that runs on submit after one has upload up to 4 files, for simplicity and testing’s sake I have focused on just managing to upload 1 file but nothing so far. I have apparently used scripts that return no error and are guaranteed to work but they did not which leads me to believe that the issue I am having has to be a permissions issue somewhere.
The platform I am running is windows server 2012, IIS 8.5, PHP 5.5, and everything else (JavaScript, html, etc..) up to date as well. Now I have tried changing the folder permissions because I was told this is the majority of the Cause, however this has not been my case. I have modified the php.ini file to allow file uploads but that did not work either. Is there a setting that I am missing somewhere deep in IIS or is something entirely different?
Thank you for your time and assistance.

berserk 60 Junior Poster

DEAR rproffitt....

THANK YOU!!!

I initially felt th name and the way form was used in the code was weird. I tried deleting it from one place and that half fixed it so then you pointed out the form name and i tinkered with that for a while, then i realized that if i just delete the form name line from each of the if statements then BLAME! all is right with rain!

berserk 60 Junior Poster

I tried using doevents and nothing, then i tried messing around with the dot cause i like the dot much better than the ! anyway, no luck anywhere, but i did end up finding a different error whe ni changed that line LabelTax6.Value = Form!CountyTax6 to LabelTax6.Value = Report_FormReport.CountyTax6, when i did this it said i couldnt assign it as a varibale, to me thats progress lol

berserk 60 Junior Poster

I dont fully understand this issue at all, it makes no sense to me for several reasons but ill liust the main ones
i have code elsewhere that works just fine and is identical in function and setup
i dont think the issue is a registry key issue, this i have checked
if the code works in those othe rplaces then why is it that it fails at the one?

here is the code

Option Compare Database

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    If NoticeLabel = "THIS IS YOUR ANNUAL NOTICE" Then
        AmountDueTotal1.Visible = False
        AmountDueTotal3.Visible = False
        AmountDueTotal6.Visible = True
        SubTotal1.Visible = False
        SubTotal3.Visible = False
        SubTotal6.Visible = True
        CountyTax1.Visible = False
        CountyTax3.Visible = False
        CountyTax6.Visible = True
        KyTax1.Visible = False
        KyTax3.Visible = False
        KyTax6.Visible = True
        TotalTax1.Visible = False
        TotalTax3.Visible = False
        TotalTax6.Visible = True
        LabelTax1.Visible = False
        LabelTax3.Visible = False
        LabelTax6.Visible = True

        LabelTax6.Value = Form!CountyTax6

'        Text312.Value = AmountDueTotal
        Label379.Caption = "6 Mo."
        Text385.Value = AmountDueTotal6
        Label389.Caption = "6 Mo."

'        Text422.Value = SubTotal6
        Label377.Caption = "6 Mo."
        Label387.Caption = "6 Mo."

        Text382.Value = KyTax6

    ElseIf NoticeLabel = "THIS IS YOUR 1 MONTH NOTICE" Then
        AmountDueTotal1.Visible = True
        AmountDueTotal3.Visible = False
        AmountDueTotal6.Visible = False
        SubTotal1.Visible = True
        SubTotal3.Visible = False
        SubTotal6.Visible = False
        CountyTax1.Visible = True
        CountyTax3.Visible = False
        CountyTax6.Visible = False
        KyTax1.Visible = True
        KyTax3.Visible = False
        KyTax6.Visible = False
        TotalTax1.Visible = True
        TotalTax3.Visible = False
        TotalTax6.Visible = False
        LabelTax1.Visible = True
        LabelTax3.Visible = False
        LabelTax6.Visible = False

        LabelTax1.Value …
berserk 60 Junior Poster

here are all the users i have currently set up
(!) <anonymous %
me %
root localhost
root 127.0.0.1
root ::1

all of these users have all global priviliges except anonymous but theres no way to change anonymous (the server made that one)
my problem might have something to do with anonymous but i am honestly not sure at this point.

i am currently using MySQL workbench 6.3 with mySQL server version 5.6 with a minimal changes made

berserk 60 Junior Poster

My problem Im almost certian is a permissions issue but im still very new to this so bare with me. I have a server running the latest mysql with mysql workbench installed and im tryign to modify the users and privilieges for either my one table or all my tables, im not sure what i need to do to get this thing working the way i want.
I have the ability to read from the database and update it thats working fine also i am about to create tables too thats something i tested out but what i cannot do is insert, which is a huge problem for me. My server is set up on IIS and i am using PHP with phpmyadmin to manage the database locally this is mainly for just quick glances to see if my submitting forms has done anything.

I dont know what i really need to do in the situation, im sure there is a permission that i have not configured correctly somehwere stopping me from inserting data into the database at least remotely over the internet.

If i did not give enough information i apologize because im literally learning this system as i go. Any help would be vastly appreciated, thank you for your time.

berserk 60 Junior Poster

thank you diafol, its funny because my solution was exactly as you say, i used a table of tables to be able to name the tables properly and reference them properly too. thanks for all the help, its been a blast figuring this out and getting ready for the end of this project!

berserk 60 Junior Poster

mainly i was doing this for organization, because i can create a new table just for that client when they register a user it will be added to that table that is associated with their account/table, i know this is a bit bulky but to me this makes sense, is there a better way to do this because i know this is probably not the norm but its a way i have found will work for my needs.

Thanks

berserk 60 Junior Poster

thanks for the pointers, i apologize for some of the errors in my code but what i was trying to accomplish was to have a user create a table and then once that table is created (within the same script) have a function take data from a temp table and copy it over to the newly created one, i wasnt sure if this was possible all in one script, and i know the table creation is resource heavy but its neccessary for the system im making. When a user registers their information is stored in a temporary table until an admin can approve the info, when this approval is done what i have described above will happen, the table will be generated for that subscriber and the data stored in the temp table will be pushed to their newly created table.

berserk 60 Junior Poster

I wasn’t sure which forum to put this under so I just selected web development. I have run into an issue that ironically I have solved before but thanks to my wonderful drop-box the changes I made were not saved and when I changed them again on another computer, the old values were kept so in a sense I lost my progress/solution. Now onto my problem.

I have a table that generates buttons to give you the option to approve or decline a user. Now the approve button calls a function that will create a database dynamically by checking to see if it already exists and if it doesn’t then it will create a new one with a new name. This is not really my problem but I felt a little explaining might clear that part of the code up. My issue is that the other function was to insert data into this newly created table and then delete the old data from the old temporary data table. This part is tricky because it will work but when I click the button to approve it will approve all of them, and I can't seem to remember how I managed to separate them before. I will include the code below to show you what I mean but any and all help is as always greatly appreciated, thanks in advance.

this is my loop to create th ebuttons dynamically

while($row=mysqli_fetch_array($query)){
                  // add one to rownumber each time
                  // get the id from …
berserk 60 Junior Poster

lol i figured it out, the issue was on my end, i was not passing my form values correctly in my loop, my rownumber reference was always 1 ahead of the function so essentially i was passing sub_id1 to a php file listening for sub_id0. i moved my rownumber counter and now it works like a charm, im sorry for the confusion, thanks for the help bnmng

berserk 60 Junior Poster

I am having no luck with this code but for some reason i can get this element to work but not the other one. here is my code.

<td><a onclick="javascript:approve_account_function(<?php echo $row['id'];?>, <?php echo $rownumber;?>)" class="btn btn-success" name="yes_account" id="yes_account">Approve</a></td>
                         <td><a onclick="javascript:decline_account_function(<?php echo $row['id'];?>, <?php echo $rownumber;?>)" class="btn btn-danger" name="no_account" id="no_account">Decline</a></td>
                         <input type="hidden" name="sub_id<?php echo $rownumber;?>" id="sub_id<?php echo $rownumber;?>" value="<?php echo $row['id']; ?>"/>
                      </tr>
                        <?php 
                      } ?>
              </tbody>
      </table>
      <input type="hidden" name="row_total" id="row_total" value="<?php echo $rownumber; ?>"/>

one thing to rememebr is that my hidden elements are being generated by a while loop so they will be different per user. This way i can pass these elements to my ajax and then through ajax pass them to the server through php, my row_total element works but my other one does not.

Here is the ajax call, there are two but they are nearly identical in function

<script type="text/javascript">

function approve_account_function(subscriber_id, rownum){
  var xhr;
    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        xhr = new ActiveXObject("Msxml2.XMLHTTP");
    }
    else {
        throw new Error("Ajax is not supported by this browser");
    }

    var note_text = $(this).attr("sub_id"+subscriber_id);
    var cnotes = $("#row_total").val(); //will be the value of loggedIn

    // var note_text=$('#row_id'+rownum).val();
    // var cnotes=$('#row_total').val();
     var lock_data = "sub_id="+note_text+"&row_total="+cnotes;

  //var lock_data = $("form#approval_form").serialize(); // gets all data from your form
  $.ajax({
    url : "http://localhost/xampp/approve_subscriber/approve_account.php",
    type: "POST",
    data: lock_data,
      success: function(data, textStatus, jqXHR)
      {
      //data - response from server
      alert(data);

      // reloads page after user clicks ok on the response …
berserk 60 Junior Poster

AHHAHA! YES i just wanted to let everyone know that i figured out what my issue was, i was appending a newly generated salt on the end of my compared hash and then doing the comparison, all i had to do was NOT hash the stored values from the database and then just hash once the values from the given input. Then i just compared the hashes and VOILA i have my magical hashy goodness. Finally i also figured out that my checkbrute fucntion was backwards, i had it set to true always so it wouldnt even make it through to the next if statement, that was my bad. Now its working great and i have some tighter security on my program, THANK YOU EVERYONE for all of you excellent assistance!!!

diafol commented: Glad you got it fixed +15
berserk 60 Junior Poster

thank you diafol, lol you always seem to be pointing me in the right direction. I have already checked into password_hash() and password_verify because i was thinking it would be easier on security if these defaults change with the php version rather than the code. Also checked your script out and wow man.. love that feeling i get when im like yeah im getting pretty good at this then i see that and im like "NOPE im still noobing pretty hard over here"

in all seriousness though i was interested in the sha512 encryption because it was the type my employer selected not that i think he would know the difference if i did go with phps simple take on it. Would there be a simple thing im doing wrong because i have gone over the logic time and time again and when i hash them (i know now its one way thank you for that knowledge) the hash i generate from using the salt i generated and saved in teh database should be the same when i apply the hash to the raw password im given, the only thing i could see that im doing wrong is hashing it one too many times somewhere but i cant see to find it. I also hash the raw input with javascript which has me wondering if that is even necessary since i sould easily just take the raw input without creating the hidden field "p" and just hashing that, clearing it …

berserk 60 Junior Poster

i did, but i cant seem to figure out why its not dehashing correctly, i rehash the values like this

function login($email, $password, $mysqli) {
    // Using prepared statements means that SQL injection is not possible. 
    if ($stmt = $mysqli->prepare("SELECT id, username, password, salt FROM approved_users WHERE email = ? LIMIT 1")) {
        $stmt->bind_param('s', $email);  // Bind "$email" to parameter.
        $stmt->execute();    // Execute the prepared query.
        $stmt->store_result();

        // get variables from result.
        $stmt->bind_result($user_id, $username, $db_password, $salt);
        $stmt->fetch();

        // hash the password with the unique salt.
        $db_password = hash('sha512', $db_password.$salt);
        $_SESSION['database_pass'] = md5($db_password);
        $password = hash('sha512', $password.$salt);
        $_SESSION['given_pass'] = md5($password);
        if ($stmt->num_rows == 1)
        {
            $_SESSION['uhoh'] = "the statement check is true and correct";
            // If the user exists we check if the account is locked
            // from too many login attempts 

            if (checkbrute($user_id, $mysqli) == true) 
            {
                // Account is locked 
                // Send an email to user saying their account is locked
                return false;
            }
            else 
            {
                // Check if the password in the database matches
                // the password the user submitted.
                if ($db_password == $password) {
                    $_SESSION['uhoh2'] = "the comparison of the password with the hashed one is true and makes it passed this check as well";
                    // Password is correct!
                    // Get the user-agent string of the user.
                    $user_browser = $_SERVER['HTTP_USER_AGENT'];
                    // XSS protection as we might print this value
                    $user_id = preg_replace("/[^0-9]+/", "", $user_id);
                    $_SESSION['user_id'] = $user_id;
                    // XSS protection as we might print this value
                    $username = preg_replace("/[^a-zA-Z0-9_\-]+/", "", $username);
                    $_SESSION['username'] = $username;
                    $_SESSION['login_string'] = hash('sha512', …
berserk 60 Junior Poster

AH HA! i have finally narrowed it down to the error but im in a new predicament, the error is in my login_verify fuinction when i go to check the hashed and salted password with the one inside the database, even though i have read plenty on it and it should be working for some reason when i echo out teh variables they are different even though they are using the same salt and be dehashed by the same encryption. WHAT GIVES :/ regardless i have found my issue thanks to the little poke jstfsklh211 gave me.

the code thats nto working looks like this

if ($db_password == $p_password) {
                    $_SESSION['uhoh2'] = "the comparison of the password with the hashed one is true and makes it passed this check as well";
                    // Password is correct!
                    // Get the user-agent string of the user.
                    $user_browser = $_SERVER['HTTP_USER_AGENT'];
                    // XSS protection as we might print this value
                    $user_id = preg_replace("/[^0-9]+/", "", $user_id);
                    $_SESSION['user_id'] = $user_id;
                    // XSS protection as we might print this value
                    $username = preg_replace("/[^a-zA-Z0-9_\-]+/", "", $username);
                    $_SESSION['username'] = $username;
                    $_SESSION['login_string'] = hash('sha512', $p_password . $user_browser);
                    // Login successful.
                    return true;
                }

and the dehashing is this

$db_password = hash('sha512', $db_password.$salt);
$_SESSION['database_pass'] = $db_password;
$p_password = hash('sha512', $p_password.$salt);
$_SESSION['given_pass'] = $p_password;

// note that the session variables are just for testing
berserk 60 Junior Poster

where is it being hashed twice? Also thank you for the input.

berserk 60 Junior Poster

I cant seem to understand the issue with this statement, admittedly i have not written this code myself but have found it and modified it to work with what im doing, as most open source code is. This is for a secure login script that will pull a salted password from the database and compare it but when its executed nothing works, and an error always returns. I dont understand this because my registration works just fine so i know my connection to my database is working right and the salt function works properly as well, but my login function seems to be misbehaving. Below is what i have so far.

function login_verify($email, $password, $mysqli) {
    // Using prepared statements means that SQL injection is not possible. 
    if ($stmt = $mysqli->prepare("SELECT id, username, password, salt FROM approved_users WHERE email = ? LIMIT 1")) {
        $stmt->bind_param('s', $email);  // Bind "$email" to parameter.
        $stmt->execute();    // Execute the prepared query.
        $stmt->store_result();

        // get variables from result.
        $stmt->bind_result($user_id, $username, $db_password, $salt);
        $stmt->fetch();

        // hash the password with the unique salt.
        $password = hash('sha512', $password . $salt);
        if ($stmt->num_rows == 1) {
            // If the user exists we check if the account is locked
            // from too many login attempts 

            if (checkbrute($user_id, $mysqli) == true) {
                // Account is locked 
                // Send an email to user saying their account is locked
                return false;
            } else {
                // Check if the password in the database matches
                // the password the user submitted.
                if ($db_password == $password) …
berserk 60 Junior Poster

so i managed to speed up the program by quite a bit, i did this by taking the scripts out of the loops first off, thats bad programming practice, i know that now. It also made things essentially uglier and harder to read. The second thing i want to do to dramatically increase the speed is simple but is not something i seem to be able to figure out on my own. I have done many searches and read and tried many different methods but none of them seem to work. I needed a way to load the details page on click without loading it in php when the page is loaded (with 5000 people that a LOT of additional php to load that essentially might not get used) so i thought i could maybe use javascript to request the page on click, since i know that php can only load on the server side.

my first method was to use pure jquery/ajax.

i did something like

function show_details(id)
{
    $.ajax({
    url: 'details.php',
    type: 'POST',
    success: function(data) {
      $('#row'+id).load(data);
      alert('Load was performed.');
    }
  });
}

but nothing, then i started looking more into onclick functions but i already have the onclick in the html, so what method will work? or am i just reading and writing the code wrong entirely?
my biggest question really is is this even possible?

any help will be (like always) both appreciated and good learning experience.

thank you

berserk 60 Junior Poster

not all of them, i was just doing testing to see how much of a load my app could handle, i was also thinking of setting up the expand option to pull data when clicked instead of pulling it before but hiding it and then showing it when clicked, a few more things i thought of doing like what you explained but how would i go about setting up a chow more users button? and also if i did a search (theres a search function at the top of my page on the right) would i still search all the users from the database or just the ones displayed on the table?

and no not all users will be displayed, in fact to be honest 200k users is really pushing it, i doubt ill exceed 5000 honestly but i just like to be prepared (luck favors the prepared) and also i was interested in learning how to handle such numbers in case i ever did need to develope something that will display such an enormous amount of data

i just really like and enjoy the way php works and would love to learn every little method i could when i can.

ALSO
JUST for the sake of cleaning my code up, is there a way to pass info to a javascript function thats outside of a loop instead of needing to use it inside the loop, i feel this is an incredibly slopy way to do this, i know …

berserk 60 Junior Poster

hello everyone, i am in need of some advice. You see i created an application to manage a large user base, this user base has additional hidden data per user that is in the form of a drop down. My problem is that 1k to 5k of users is fine, the app handles well within reason and is completely usable BUT when i hit number like 20k 50k and 200k thats when my speed truly suffers. Is there a way to speed this up, this is currently the method im using to populate and create the data in the database on a table

<table>
    <tbody>

$query=mysqli_query($con, "SELECT * FROM userprofile")or die(mysqli_error($con));

while($row=mysqli_fetch_array($query)){
$id=$row['id'];

<script>
                        function changeText(idElement) {
                            var element = document.getElementById('back' + idElement);
                            // this script is for processing each HTML element of a specific string and changing it on user click
                            // I used echo row-number as a way to go through each row to find the proper label, in my case should be the first header
                          for (var i = 0; i <= <?php echo $rownumber;?>; i++) {
                            i = i++;
                            if (idElement === i) {
                                if (element.innerHTML === '[+]') element.innerHTML = '[_]';
                                else {
                                    element.innerHTML = '[+]';
                                }
                            }
                          }
                        }
                        </script>
<tr>
                          <td width="5%"><center>
                            <div title="Show more Details for <?PHP echo @$row['username'];?>">
                            <!-- I used php echoes to get the data stored in my php script and use it in my html/javascript -->
                            <!-- this individual column is important because it has all the functionality for …
berserk 60 Junior Poster

I have done some research and found out the reason my javascript was not working was that my input boxes were set up in an array and i need them to be in an array to work right so i have to use php session variables to do this correctly. Sorry for the wasted time everyone :(

berserk 60 Junior Poster

welp im stuck again, this solution i thought was working was not hat i was looking for and now im back to the drawing bored. Im not sure how to get your code to work AleMonterio i keep working and working at it but i dont seem to get any response or really any type of change. whats really confussing is that i am also not getting any errors... im kinda t a lose here :(

berserk 60 Junior Poster

okay now im getting more and more curious about this, i just found out that cookies are working FINE because in the code i posted above if you change the

" var test = localStorage.input === 'true'? true: false; "
to this
" var test = localStorage.input = 'true'? true: false; "

you can forcfully create a cookie and store all the checkbox values as true, the issue with this is that no matter what they are all going to be true
so at least i know that part is working, so really my issue is in something with the checkbox values not storing and checked as true or false but why?

berserk 60 Junior Poster

i think i might have an idea, using the old code from above earlier i noticed something thats rather strange

in this code no matter what i do, it always comes back false, so that tells me that the input is changing but not being seen by the javascript

$(function(){
    var test = localStorage.input === 'true'? true: false;
    $('input').prop('checked', test || false);
    alert(test);
});

$('input').on('change', function() {
    localStorage.input = $(this).is(':checked');
});

that alert always comes back false, so at least i know that the function is being called but now i know that no matter whats its coming back false because the checkboxes are not connected to the function, is it a naming issue? or an id issue? i mean i figured since this was for ALL input checkboxes on the page it wouldnt matter. HEY i think we made some progress lol!

i got no errors from the console BUT i am referencing jquery AND jquery cookie those i know are in there!

berserk 60 Junior Poster

still nothing, i dont understand why its not working in my code but it works just fine in JSfiddle, is it the ajax calls? whats different?

also im prepared to justuse $_get ajax and forget about the localstorage cause i dont seem to be getting anywhere with this and i really cant see the reason why :(

berserk 60 Junior Poster

I apologize for my confussion im just not that comfortable with JS yet, YET! but i have wrapped my code inside a script tag already, and the only real difference is that it wasnt inside the function call you listed. Now it is but i still seem to get nothing from the page. im going to include all that i can of my page because it has to be something im doing, these codes are working fine in JSfiddle and since its not working inside my code its confussing me and i really dont want it to.

here is the code i can incluse in full
(also note that i am including all my libraries like jquery but they are in another file but they work fine)

$con = mysqli_connect($host,$uname,$pass,$database) or die(mysqli_error($con));
?>
<script type="text/javascript">

function print_notice(){
  // var note_text=$('#note_text').val();
  // var cnotes=$('#cnotes').val();
  // var  formData = "note_text="+note_text+"&cnotes="+cnotes;
  var xhr;
    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        xhr = new ActiveXObject("Msxml2.XMLHTTP");
    }
    else {
        throw new Error("Ajax is not supported by this browser");
    }

  var notice_data = $("#print_notice_form").serialize(); // gets all data from your form

  $.ajax({
    url : "http://localhost/xampp/process_notice/print_notice/mpdf/examples/print_notice.php",
    type: "POST",
    data: notice_data,
      success: function(data, textStatus, jqXHR)
      {
      //data - response from server
      alert(data);

      // reloads page after user clicks ok on the response
      location.reload(true);
    },
  });

}

function print_coversheet(){
  // var note_text=$('#note_text').val();
  // var cnotes=$('#cnotes').val();
  // var  formData = "note_text="+note_text+"&cnotes="+cnotes;
  var xhr;
    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    } …
berserk 60 Junior Poster

I see what you mean now witht he get data functionality for ajax, i didnt know about that before, i will see what i can come up with to avoid the page refresh entirely, that actually would ultimatly solve my issue lol

also AleMonterio i tried the code you made, what i dont get is in JSfiddle it works just fine but in my program it does nothing? whats up with that?

also i mean if i can avoid having to refresh the page all together thats fine too but i would still like to figure this out for educational purposes just in case i ever come across it again.

but for now the none refresh will work, is the get function the same and the post in ajax?

berserk 60 Junior Poster

to answer diafols question, i used the reload in ajax cause i needed to update values in my table after printing something off. I know its odd because usually you use ajax for the soul purpose of not refreshing, lol i admit thats an odd one but it seems to do what i want. if you know of a better way then please let me know, like i said before im still learning ajax, and i find incredibly useful :D.

In response to AleMonterio, I used your code but couldnt get anything to work, would there be something im not including in all this to show what im doing wrong? Im still very confused :/

in response to JoshuaJames.delecruz, that solution was the first one I tried when i started doing this, it didnt work for me :/

berserk 60 Junior Poster

I have found several different methods for doing this online but for some reason i just cant get any of them to work for me, it may be they way im calling them or something but it also might involve my lack of expereince with JS but regardless I have decided to reach out.

here is the code i have found and so far is the only code that seems to give me a reaction on my page

$(":checkbox").on("change", function(){
  var checkboxValues = {};
  $(":checkbox").each(function(){
    checkboxValues[this.id] = this.checked;
  });
  $.cookie('checkboxValues', checkboxValues, { expires: 7, path: '/' })
}

function repopulateCheckboxes(){
  var checkboxValues = $.cookie('checkboxValues');
  if(checkboxValues){
    Object.keys(checkboxValues).forEach(function(element) {
      var checked = checkboxValues[element];
      $("#" + element).prop('checked', checked);
    });
  }
}

$.cookie.json = true;
repopulateFormELements();

This code will work im sure i just cant seem to get it to run right with the rest of my Javascript

here is my HTML, please don’t judge me on hideous code lol

<?php 
                            $query=mysqli_query($con, "SELECT * FROM userprofile")or die(mysqli_error($con));
                            $rownumber= NULL;
                            while($row=mysqli_fetch_array($query)){
                            $rownumber++;
                            $id=$row['id'];
                            ?>
                            <script type="text/javascript">

                            function checkOne<?php echo $id; ?>(){
                                if(    document.getElementById('<?php echo $id; ?>').checked $$ document.getElementById('chkSelectDeselectAll').checked){
                                     document.getElementById('chkSelectDeselectAll').checked = true;
                                }
                                else{
                                     document.getElementById('chkSelectDeselectAll').checked = false;
                                }
                              }
                              </script>
                                        <tr>
                                         <td style="text-align:center;">
                                         <input type="checkbox" id="<?php echo $rownumber; ?>" onclick="checkOne<?php echo $id; ?>()" name="selector[]" value="<?php echo $id; ?>">
                                         </td>
                                         <td><?php echo @$row['subscriber_acct_#'] ?></td>
                                         <td><?php echo @$row['company_name_sos'] ?></td>
                                         <td><?php echo @$row['username'] ?></td>
                                         <td><?php echo @$row['contact'] ?></td>
                                         <td><?php echo @$row['phone'] ?></td>
                                         <td><?php echo @$row['name'] ?></td>
                                         <td><?php echo @$row['account'] ?></td>
                                         <td><?php echo @$row['repo_sale_date'] ?></td>
                                         <td><?php echo …
berserk 60 Junior Poster

lol with enough time and effort the solution can be found, and while this solution isnt the best it works just fine, though it may be a little hard to read without some commenting since this is a very unique solution to this problem. I am not promoting this solution as the only way this is simply the method i figured out through lots of reading and running through example code.

here is the script inside my html, this is ajax but has been modified to be generated inside a loop since the note system i had in place is for multiple users inside a table.

<script>
                            function no_redirect<?php echo $u;?>(){
                              // var note_text=$('#note_text').val();
                              // var cnotes=$('#cnotes').val();
                              // var  formData = "note_text="+note_text+"&cnotes="+cnotes;
                              var xhr;
                                if (window.XMLHttpRequest) {
                                    xhr = new XMLHttpRequest();
                                }
                                else if (window.ActiveXObject) {
                                    xhr = new ActiveXObject("Msxml2.XMLHTTP");
                                }
                                else {
                                    throw new Error("Ajax is not supported by this browser");
                                }

                              var datanote<?php echo $u;?> = $("#note_form<?php echo $u;?>").serialize(); // gets all data from your form

                              $.ajax({
                                url : "addnote.php",
                                type: "POST",
                                // data : formData,
                                data: datanote<?php echo $u;?>,
                                  success: function(data, textStatus, jqXHR)
                                  {
                                  //data - response from server
                                  alert(data);
                                },
                              });

                            }
                            </script>

below is the php code i used, it works but is definitly a rough solution, use with caution.

$con = mysqli_connect($host,$uname,$pass,$database) or die(mysqli_error($con));

$customer_notes                     = NULL;
$row                                = NULL;
$totalrow                           = NULL;

$totalrow                           = $_POST['totalrow']; // get total row for the number of times the loop below needs to run …
diafol commented: Thanks for coming back with it +15
berserk 60 Junior Poster

XD LMAO i knew id get that kind of reaction. I literally just went on a for loop tangent to see if i could get the individual note entries to work for each user instead of just the last user, but it obviously did not work. I apologize for (how my old college professor would put it) UGRY COHDE!

berserk 60 Junior Poster

OKAY i have made a huge amount of progress but now im stumped and i dont know whay its not working. I managed to get the form posting data too and from the database but for some reason it only does the last bit of the form and not the other nested forms that are generated by my loop inside the html file. here is what i have so far, it works for the last entry on the table and will post and update the data i put into that form but will not work on all the other forms that i have, i must be missing something small because i feel like im SOOOO close to figuring out why this isnt working since its working correctly for the last entry in the table.

here is the html code i have come up with.

<script>
                            function no_redirect(){
                              // var note_text=$('#note_text').val();
                              // var cnotes=$('#cnotes').val();
                              // var  formData = "note_text="+note_text+"&cnotes="+cnotes;

                              var xhr;
                                if (window.XMLHttpRequest) {
                                    xhr = new XMLHttpRequest();
                                }
                                else if (window.ActiveXObject) {
                                    xhr = new ActiveXObject("Msxml2.XMLHTTP");
                                }
                                else {
                                    throw new Error("Ajax is not supported by this browser");
                                }

                              var datanote = $("#note_form<?php echo $u;?>").serialize(); // gets all data from your form

                              $.ajax({
                                url : "addnote.php",
                                type: "POST",
                                // data : formData,
                                data: datanote,
                                  success: function(data, textStatus, jqXHR)
                                  {
                                  //data - response from server
                                  alert(data);
                                },
                              });

                            }
                            </script>

                            <form action="#######.php" method="POST" id="note_form<?php echo $u;?>">
                            <div class="span12">
                              <h4 style="color:#1577a6;">Notes</h4>

                              <input type="hidden" name="cnotes<?php echo $u;?>" id="cnotes<?php echo $u;?>" value="<?php echo …