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
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 ";

  }
}

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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