0

I have this array below.

$LOGIN_INFORMATION = array(
  'user1' => 'user1password',
  'user2' => 'user2password'
);

And I want to make the array so that it loads all the username and passwords from a datbase instead. How could I do that? Any help is appreciated.

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by rajarajan07
0

Perform a query. As you loop through the return append each return record to the array. That should be all it takes.

Although, from a design standpoint, I'm not too sure this is a good idea. It has the potential to be a HUGE security risk. If a malicious user successfully inserts the proper PHP commands into your login form, they suddenly have access to every username in your database and their associated passwords.

Edited by Fbody: n/a

0

Yeah I was trying to do that accept I am not sure on the actual syntax for it.

Perform a query. As you loop through the return append each return record to the array. That should be all it takes.

Although, from a design standpoint, I'm not too sure this is a good idea. It has the potential to be a HUGE security risk. If a malicious user successfully inserts the proper PHP commands into your login form, they suddenly have access to every username in your database and their associated passwords.

0

This is how I did it on a site that I built a while ago:

while ($skill = @mysqli_fetch_assoc($lookup))
  {
  $captures[$skill['eliteId']] = $skill['eliteName'];

  // END ARRAY BUILD WHILE LOOP
  }

This dynamically generates an array similar to
$captures[1] = "Name 1"
$captures[2] = "Name 2"
$captures[3] = "Name 3"
$captures[5] = "Name 5"
$captures[7] = "Name 7"

It seems to work really well...

Edited by Fbody: n/a

0

Thanks that worked for me I modified it a little bit, and worked great. thanks a lot.

This is how I did it on a site that I built a while ago:

while ($skill = @mysqli_fetch_assoc($lookup))
  {
  $captures[$skill['eliteId']] = $skill['eliteName'];

  // END ARRAY BUILD WHILE LOOP
  }

This dynamically generates an array similar to
$captures[1] = "Name 1"
$captures[2] = "Name 2"
$captures[3] = "Name 3"
$captures[5] = "Name 5"
$captures[7] = "Name 7"

It seems to work really well...

0
Instead of this
$captures[$skill['eliteId']] = $skill['eliteName'];
you can also use:
array_push($captures, $skill['eliteName']);
0
Instead of this
$captures[$skill['eliteId']] = $skill['eliteName'];
you can also use:
array_push($captures, $skill['eliteName']);

I was not aware of that function, I'll keep it in mind in the future. Based on my research though that does not set up the array elements the way I need them set up. This creates consecutively numbered elements that contain $skill as values.

The problem is, if you look at the example, the elements' indexes are not consecutive, they are in numeric order, but they are not consecutively numbered. A very specific ID needs to be associated with each element. They need to be this way because of the way in which the data in the array is selected, generated, and used.

I suspect that the OP has a similar situation.

Edited by Fbody: n/a

0

Thats Right! I am not looked into that non-consecutive. Thanks. As you said you not aware of that function. Let trigger you that is also an array function we can used to push the elements as a consecutive one. COOL!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.