Jump to content

getting data from php array


thunder708

Recommended Posts

hi all!

 

right i have two files, login.php and users.php.

 

users.php

<?
$user = array();
// Set Users
$user[0]["name"]='liam';
$user[0]["pass"]='lol';
$user[1]["name"]='mike';
$user[1]["pass"]='rofl';
?>

 

and in the login.php i have a form that you type in a user and pass and it logs you in, i know how to do this if i set the values within the login file itself but i want to be able to use this array i have made.

 

so my question is, how do i search the array for the required user and pass when it is submitted from the form?

 

 

Link to comment
https://forums.phpfreaks.com/topic/193950-getting-data-from-php-array/
Share on other sites

$user = $_REQUEST['user']; // requests user from form
$pass = $_REQUEST['pass']; // requests pass from form

include("users.php");

foreach ($users as $u) {
if ($u['name'] == $user && $u['pass'] == $pass) {
echo "well don eyou have logged in ";

  }
}

i have figured out what i have done wrong, i had changed your code to say

 

foreach ($users as $u) {

 

and changed the users file to say

 

$users[0]["name"]='liam';
$users[0]["pass"]='lol';

 

but forgot to change the declaration to

$users = array();

 

 

it was still

$user = array();

 

 

my bad

 

thank you anyway

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.